How to debug LLVM code using lldb? - llvm

I have a piece of hand-written llvm assembly that I want to debug with lldb.
How do I make llc emit debugging information so that lldb could display the original llvm assembly instead of the native at&t-style assembly it's displaying at the moment?

There used to be a pass called DebugIR that would add debug info to LLVM IR, however it was removed in r222945. My guess is that it wasn't maintained properly and was bit-rotting. You could try revive it though!

Related

GDB shorten function signatures when using layout spilt?

I am using layout split within GDB to preview the source code above the assembly code. However, in the bottom panel (the assembly viewer) each instruction address is prefixed with the corresponding C++ function/method signature. The problem is some of my functions have 8/9 arguments and this is causing the signature to be huge, requiring me to open GDB across two monitors, just to see the assembly instructions.
Are there any GDB options to shorten the signature/replace it with something shorter?
gdb --version returns GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-100.el7_4.1

GDB debugger switch platform (cortex-m3)

I have previously installed GDB to debug C in eclipse, which is working perfectly. I want to do the same now with my cortex m-3, however I can't make a binary object using GDB because it is giving me an error.
I want to make a binary file the following way:
as -mcpu=cortex-m3 -mthumb example1.s -o example1.o
It does not recognize my cortex-m3 and it is giving me the following error:
as: unrecognized option `-mcpu=cortex-m3'
When doing a version check with my GDB it says the following:
This GDB was configured as "x86_64-w64-mingw32".
Is there a way to switch this to arm-none-eabi?
I hope someone can help me.
This isn't really a question about gdb. gdb is the debugger. as is the assembler.
You want to build or get a cross-assembler.
Well, actually it WAS a question about the GDB, because I did not really understand how it worked. I have fixed it now.
I have moved my assembly file to the folder containing my Atollic GDB debugger for ARM processors and did the same command. He interpreted the right MCPU, and the binary file has been made now.

How to stop gdb stepping through intrinsic functions in Fortran code?

I'm debugging some Fortran code with gdb and it keeps stepping through the C code for intrinsic Fortran functions. For example if I try to step past a write call, it jumps into write.c. Is there any way to stop this behaviour? I'm on CentOS 6.3, with gdb 7.2 and gfortran 4.4.
Normally I think "next" should work. But I don't know Fortran, maybe something funny is going on.
Another way is to ensure that you don't have debug info for the intrinsics installed. gdb will automatically skip over functions that don't have debuginfo if you try to "step" into them.
The final way is to upgrade your gdb and use the new "skip" command, which was added exactly for this use case.
I had a problem like this where next wasn't working when I was remote debugging on a cross-compiled target. I finally realized that I had loaded the wrong executable/symbol table using gdb's file command. Hitting next was jumping in to places un-releated to the current line of code. It was doing the best it could given the information I gave it :)

Setting disassembly flavour to Intel in LLDB

Is there a way to set the disassembly flavour like there is in GDB within LLDB so that it spits out Intel style assembly rather than AT&T style?
set disassembly-flavor intel # GDB
but for LLDB.
The exact line to write in your ~/.lldbinit file is
settings set target.x86-disassembly-flavor intel
In the future, you will also be able to tweak how immediate values are displayed with the new settings: target.use-hex-immediates and target.hex-immediates-style.
No, not yet. Intel format disassembly is a feature I'm sure will be implemented eventually, but I don't think anyone is working on it today.
UPDATE: the ability to select the assembly style was added to the top of tree sources (v. http://lldb.llvm.org ) March 1st, 2013 with the -F or --flavor option to disassemble or the target.x86-disassembly-flavor setting in your ~/.lldbinit file. This will be available in future releases of lldb in Xcode.

Debugging an application in Linux

I want to debug an application in Linux.
The application is created in C++. The GUI is created using QT.
The GUI is linked with a static library that can be treated as the back end of the application.
I want to debug the static library but am not sure how to do that.
I tried using gdb
gdb GUI
But how can I attach the library?
Has anyone had experience in debugging libraries in linux?
gdb will automatically debug functions in the library when they are called. just call it like
gdb ./foo
run
:) . Be sure you build foo with debugging flags (-g3 will enable all debugging stuffs for gcc :). You should not optimize when debugging (pass at most -O1 to gcc, do not optimize further). It can confuse the debugger.
If you want to debug the library code itself, you'll need to build the library with the -g compiler flag (as well as building the executable with -g as litb pointed out). Otherwise gdb will step through your code fine but will throw up its hands each time you make a library call.
You can Try KDbg, DDD - Data Display Debugger, Code::Blocks
Ulike DDD, others are IDE with debugger integrated but core debugger [gdb] remains same in those IDE. only thing is that you will get oragnized view of debugger view in GUI.
Also try Eclipse+CDT pluggin. it's also good.
A little-known alternative is gdbtui which uses a curses based interface.
You can also use Kdbg or ddd