I'm having trouble debugging x86 code generated by LLVM. GDB does work with the code, but not correctly, for example, the "next" command does not skip over a function call. Here's an example. Source program gdb1.c: int x; void foo(){ x++; } void bar(){ x--; } int main(){ foo(); bar(); return 0; } commands: $ llvm-gcc -g -emit-llvm -c gdb1.c -o gdb1.bc $ llc gdb1.bc $ gcc -m32 gdb1.s -o gdb1 $ gdb ./gdb1 GNU gdb Red Hat Linux (6.6-16.fc7rh) Copyright (C) 2006 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu"... Using host libthread_db library "/lib64/libthread_db.so.1". (gdb) b main Breakpoint 1 at 0x80483a0: file /home/mcmillan/projects/impact2/test//gdb1.c, line 11. (gdb) run Starting program: /home/mcmillan/projects/impact2/test/gdb1 Breakpoint 1, main () at /home/mcmillan/projects/impact2/test//gdb1.c:11 11 int main(){ (gdb) next main () at /home/mcmillan/projects/impact2/test//gdb1.c:12 12 foo(); (gdb) foo () at /home/mcmillan/projects/impact2/test//gdb1.c:4 4 x++; (gdb) 5 } (gdb) main () at /home/mcmillan/projects/impact2/test//gdb1.c:13 13 bar(); (gdb) bar () at /home/mcmillan/projects/impact2/test//gdb1.c:8 8 x--; (gdb) 9 } (gdb) Notice the "next" causes gdb to step into "foo" instead of stepping over it. Also, notice that I used -m32 on the gcc command line to assemble the LLVM-generated source file. This seems to be needed, though I don't know why LLVM would be generating 32-bit code on my 64-bit machine. Versions: LLVM 2.5 (though got same result with 2.2), gcc 4.1.2, gdb 6.6, running on x86 Linux (Fedora 7). Has anyone had similar issues with gdb? Is debugging with gdb known to work properly on other platforms? Thanks for any help -- Ken McMillan -- View this message in context: http://www.nabble.com/problems-with-dwarf-gdb-tp23033690p23033690.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On Apr 13, 2009, at 11:00 PM, Ken McMillan <kenmcmil at yahoo.com> wrote:> > I'm having trouble debugging x86 code generated by LLVM. > GDB does work with the code, but not correctly, for example, > the "next" command does not skip over a function call.This is a known limitation on debug info generated by llvm, at least as per Darwin Gdb. - Devang> > Here's an example. > > Source program gdb1.c: > > int x; > > void foo(){ > x++; > } > > void bar(){ > x--; > } > > int main(){ > foo(); > bar(); > return 0; > } > > commands: > > $ llvm-gcc -g -emit-llvm -c gdb1.c -o gdb1.bc > $ llc gdb1.bc > $ gcc -m32 gdb1.s -o gdb1 > $ gdb ./gdb1 > GNU gdb Red Hat Linux (6.6-16.fc7rh) > Copyright (C) 2006 Free Software Foundation, Inc. > GDB is free software, covered by the GNU General Public License, and > you are > welcome to change it and/or distribute copies of it under certain > conditions. > Type "show copying" to see the conditions. > There is absolutely no warranty for GDB. Type "show warranty" for > details. > This GDB was configured as "x86_64-redhat-linux-gnu"... > Using host libthread_db library "/lib64/libthread_db.so.1". > (gdb) b main > Breakpoint 1 at 0x80483a0: file > /home/mcmillan/projects/impact2/test//gdb1.c, line 11. > (gdb) run > Starting program: /home/mcmillan/projects/impact2/test/gdb1 > > Breakpoint 1, main () at /home/mcmillan/projects/impact2/test// > gdb1.c:11 > 11 int main(){ > (gdb) next > main () at /home/mcmillan/projects/impact2/test//gdb1.c:12 > 12 foo(); > (gdb) > foo () at /home/mcmillan/projects/impact2/test//gdb1.c:4 > 4 x++; > (gdb) > 5 } > (gdb) > main () at /home/mcmillan/projects/impact2/test//gdb1.c:13 > 13 bar(); > (gdb) > bar () at /home/mcmillan/projects/impact2/test//gdb1.c:8 > 8 x--; > (gdb) > 9 } > (gdb) > > Notice the "next" causes gdb to step into "foo" instead of stepping > over it. > > Also, notice that I used -m32 on the gcc command line to assemble > the LLVM-generated source file. This seems to be needed, though > I don't know why LLVM would be generating 32-bit code on my > 64-bit machine. > > Versions: LLVM 2.5 (though got same result with 2.2), gcc 4.1.2, > gdb 6.6, running on x86 Linux (Fedora 7). > > Has anyone had similar issues with gdb? Is debugging with gdb > known to work properly on other platforms? > > Thanks for any help -- > > Ken McMillan > > > > > -- > View this message in context: http://www.nabble.com/problems-with-dwarf-gdb-tp23033690p23033690.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Hi Ken, Ken McMillan wrote:> I'm having trouble debugging x86 code generated by LLVM. > GDB does work with the code, but not correctly, for example, > the "next" command does not skip over a function call. > > Here's an example. > > Source program gdb1.c: > > int x; > > void foo(){ > x++; > } > > void bar(){ > x--; > } > > int main(){ > foo(); > bar(); > return 0; > } > > commands: > > $ llvm-gcc -g -emit-llvm -c gdb1.c -o gdb1.bc > $ llc gdb1.bc >Try llc -disable-fp-elim gdb1.bc -Argiris
Argiris Kirtzidis wrote:> > ... > > Try > llc -disable-fp-elim gdb1.bc > >Thanks, I would never have guessed that :-). Are there any other optimizations that are harmful to debug info that I should know about? Thanks -- Ken -- View this message in context: http://www.nabble.com/problems-with-dwarf-gdb-tp23033690p23049871.html Sent from the LLVM - Dev mailing list archive at Nabble.com.