Unable to view symbols when debugging GNU Fortran in LLDB - macos

This is a follow-up question to a question posted previously on stack overflow.
When I compile with the -g (or -gdwarf-2) flag in GNU Fortran (GNU Fortran (MacPorts gcc5 5.3.0_0) 5.3.0) I am unable to examine symbols. If I use the "frame variable" command I do not get the list of local variables. If I use the "print" command with a symbol, nothing is printed.
I can get breakpoints to work by using the appropriate name (I look at the output from nm to get the mangled name). The source code is displayed in the debugger, so lldb is understanding at least some of the debugging information.

lldb has no support for Fortran at present. In particular, since lldb relies on the clang/swift type system representations, which also don't support Fortran, the expression parser won't work at all. There is Go support that gets frame variable working without having to make a full Go clang frontend. That same path could be followed to get some Fortran support. But there's nobody working on this that I am aware of.

Related

GDB or Radare2?

Should I use GDB or Radare2 for reversing an executable(I am a beginner)?
I try to programming in C and I got a SegFault. I want to Reverse Engineer it to get experience in Assembly and see where I get the SegFault.
For debugging an executable you built from source yourself, GDB is intended as a debugger. You can use layout reg to get a disassembly + registers view which can help understanding segfaults, if looking at C variables didn't help.
Debug info from compiling with gcc -g means you don't need to reverse-engineer anything, just use a normal debugger. But to get experience in asm, using a debugger both ways (source view and asm view) can help you understand how the compiler used certain asm instructions to implement each C statement. So you definitely want a debugger that can take advantage of debug info. There are some GUI GDB front-ends, like https://www.gdbgui.com that can be easier to use than command-line GDB.
But see also How to remove "noise" from GCC/clang assembly output? for more about seeing how C compiles to asm.
I haven't used radare2. I assume it has features that are good for intentionally-obfuscated executables without source, which is the opposite of what you have from compiling your own C programs with a normal compiler.
I would recommend Radare2 because it's clearer than GDB and easier for beginners ;)

How to instruct GDB to put breakpoints in all of my functions without becoming slow?

I have an executable that was built from a lot of *.c and *.h files. When I use the following GDB command to add breakpoints:
rbreak .
it does the job, but it takes a VERY long time to finish, because it wants to put breakpoints in libc, openssl and other functions from 3rd party libs that I really don't care about.
How can I put these breakpoints quickly in my functions?
Here are some ideas how that could be achieved, but I am not sure if GDB supports any of them
instruct GDB not to put breakpoints in 3rd party libs; or
by silencing GDB's confirmation for each added breakpoint (it gets printed to console and may slow things too).
somehow match regex on files when invoking the rbreak command?
Note that my functions don't have a naming pattern that could be matched with a regular expression.
instruct GDB to put breakpoints in all of my functions
In general, this request suggests that you may have an XY problem. I've been using GDB for over 20 years for all kinds of programs, and I am hard pressed to think of a reason to want to do what you want to do.
That said, apparently newer versions of GDB support rbreak foo.cc:.* syntax, as this answer indicates. See also this answer for an alternate recipe.
Update:
What I am trying to do by putting all these breakpoints is to use gdb as tracer
Ok, you do have an XY problem. Instead of using GDB as a tracer, compile in an actual tracer -- it will be a 1000 times faster and will just work(TM). Instructions here and here.

How to print the compiled instructions in V8 engine?

I have compiled the v8_hello_world sample and it could print "hello world" in the console. I know that V8 compiles the JavaScript with JIT, but I want to print the detailed message such as instructions it compiled. And I also want to know the types of these instructions, so what should I do?
Thank you very much~
Depending on the type(s) of generated code you're interested in, you'll have to pass the corresponding flag(s) to V8:
--print-code prints unoptimized machine code (created by "full codegen", the unoptimizing compiler)
--print-bytecode prints bytecode (created by the "Ignition" interpreter)
--print-opt-code prints optimized machine code (created by either the "Crankshaft" or "TurboFan" optimizing compilers)
These flags (and many others) are documented by --help. Since major changes to the execution pipeline are currently ongoing, depending on which version of V8 you're using, you might see the same function compiled by different compilers.
If you use the developer shell d8, you can pass these flags directly on the command-line. In your own embedding application, you can use v8::V8::SetFlagsFromCommandLine to pass argc and argv to V8. In d8.cc you can see an example for how to handle some flags yourself and pass on others to V8.
Update one year later: "full codegen" and "Crankshaft" are gone. --print-bytecode still prints bytecode, --print-opt-code prints optimized machine code (now always from "Turbofan"). --print-code has less to do than before, but is still useful for generated regexp code and wasm code.

Xcode 6, print the value of a define in the LLDB console?

It is possible to check the value of a DEFINE using a command in the lldb window?
I presume you mean C preprocessor defines? While there is a format for recording preprocessor defines & macros in DWARF, which is the default debug information format for gcc & clang and the only one lldb supports, for most substantial programs the resultant increase in debug info size is so great that it really isn't practical to use it. gcc does emit it (though doing so is not the default) and last time I played around with it gdb had spotty but functional support for macro information . But clang has never supported writing DWARF macro information, and lldb doesn't support it either.

assembly programming in Emacs how to?

assembly programming in Emacs how to?
I want Emacs to do following things
1. assembling
2. run the just before made program inside Emacs
3. debugging with watching flags and registers as like ollydbg or softice
4. decompile executable file for see what assembly codes are made by c
but I don't know how to do this
could somebody let me know ?
Which operating system (and machine architecture) are you using? I think that's quite essential information for questions about assembly programming.
I'll try to answer your four points anyway:
Just run your assembler (e.g. as) from M-x compile.
Run it from a shell buffer or from shell-command (bound to M-!).
Emacs' built-in graphical debugging support is started with M-x gdb. You may have to look for some external debugger support package if GDB is not suitable for your purposes.
For disassembling object code, I'd use GDB. But I think if you have the C sources, it would be better to compile them with the -S flag to see the assembly code emitted by the compiler instead of what can be reconstructed from the machine code.
Since you mention SoftICE, I'm assuming you're on windows.
(Good old times, by the way. If anybody ever used SoftICE on windows 9x, he/she will know what I mean :)
I don't use Emacs, but here's how to get started:
Get the tools you need to assemble your program (ie: at least, the assembler and the linker). On windows, the MASM package comes with everything you need : http://www.masm32.com/
Figure out wich commands you need to compile a simple hello world.
Configure Emacs so that it runs the above commands for you

Resources