I use openSUSE as my OS,and gdb 7.5. I want to debug my programs with gdb, with breakpoints. But when I make a breakpoint, and then run my program, gdb informs me as follows :
Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".cpp"
Its same in all of my programs. Also, when run to the breakpoint ,the program doesnt' stop at all. Can any one tell me what's wrong?
I download the latest gdb and install it ,the former message is gone ,but when run gdb it tells me that :
warning: Could not load shared library symbols for linux-gate.so.1. Do you need "set solib-search-path" or "set sysroot"?
how to slove this problem?
There is a known bug in gdb 7.5 where the debugger fails to parse the linespec when the source file name starts with a decimal digit. See this message for details.
Try renaming the file and update gdb from your distribution repository. If the bug persists, file a bug with your distribution maintainers.
See a sample session from a bug report submitted to gdb bugzilla.
(gdb) b 3
Breakpoint 1 at 0x4004c3: file 2.c, line 3.
(gdb) r
Starting program: /home/teawater/tmp/a.out
Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".c"
Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".c"
Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".c"
Error in re-setting breakpoint 1: malformed linespec error: unexpected string, ".c"
I use "b + linenumber"
This defines a breakpoint relative to the current line, see als Specifying a Location. With the code from your comment below, the following would work:
$ gdb ./main
(gdb) b +5
Breakpoint 1 at 0x40139c: file main.cpp, line 6.
(gdb) run
[New Thread 1528.0x1930]
Breakpoint 1, main () at main.cpp:5
5 while(scanf("%d%d",&a,&b)!=EOF)
Unless there is a good reason to specify relative line numbers, I suggest that you use absolute line numbers or function names:
(gdb) b main
Breakpoint 1 at 0x401395: file main.cpp, line 3.
(gdb) b main.cpp:6
Breakpoint 1 at 0x40139c: file main.cpp, line 6.
Related
I am trying to step into a method within a class through gdb. So currently, my gdb works for standalone functions. I can step into them fine, however, when I try to step into a method, it doesn't step into it. Here's my script:
#include <iostream>
using namespace std;
class test{
public:
void say_hello(){
cout<< "hello";
}
};
int main(){
test t;
t.say_hello();
return 0;
}
Here's what gdb spits out right after I press run the "run" command.
warning: `/BinaryCache/coreTLS/coreTLS-35.40.1~1/Objects/coretls.build/coretls.build/Objects-normal/x86_64/system_coretls_vers.o': can't open to read symbols: No such file or directory.
warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_ciphersuites.a"
warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_handshake.a"
warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_record.a"
warning: Could not open OSO archive file "/BinaryCache/coreTLS/coreTLS-35.40.1~1/Symbols/BuiltProducts/libcoretls_stream_parser.a"
Here's what happens when I try stepping:
Breakpoint 1, main () at test.cpp:13
13 t.say_hello();
(gdb) s
14 return 0;
(gdb)
0x00007fff91eec5c9 in start () from /usr/lib/system/libdyld.dylib
(gdb)
Single stepping until exit from function start,
which has no line number information.
hello[Inferior 1 (process 9896) exited normally]
If it makes any difference, when I run g++ --version, I get Apple LLVM version 7.0.0.
Thanks.
By default, GDB steps over functions which contain no debug information. But it is clear that you have it, since you see "at test.cpp:13" when you break on main().
My guess is that you have an older version of GDB that does not fully understand symbols generated by your compiler, and thus fails to step into member functions.
If I were you, I would first try to debug your program with lldb (since you already have it on your system) and see if it goes well. And if it does, then the issue is indeed with an old GDB, so I would upgrade to a later version.
I created a Hello World example in C++ and tried to debug it with lldb from the terminal on Mac OSX.
> lldb a.out
Current executable set to 'a.out' (x86_64).
I can set breakpoints on names (eg. 'main'), but not on line numbers. If I try
breakpoint set --file test.c --line 5
or
b test.c:5
I get
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
The file 'test.c' is located in the current folder. What goes wrong?
Acording to Dwarf Debugging Information Format, the line number, file location information are stored in the Dwarf format. Such information is what GDB used to set line number as a breakpoint.
Usually, the Dwarf format information is generated by compiler, such as GCC with the -g options. Please try with -g options to see whether it works.
Meanwhile, there also some other debug helpful options in GCC which might be more helpful to you, such as -g3, compiler will generate more detail information for debug, such as macros.
trace point can be traced, but trace actions does not work normally.
at the last of gdb side below shows trace point is traced.
but "collect $regs" does not work as expected.
my platform is RH6.4.
1. gdbserver side.
gdbserver :10000 ./a.out
Process ./a.out created; pid = 10466
Listening on port 10000
Remote debugging from host 127.0.0.1
2. gdb side.
gdb a.out
(gdb) target remote :10000
Remote debugging using :10000
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00000033b7000b00 in _start () from /lib64/ld-linux-x86-64.so.2
Created trace state variable $trace_timestamp for target's variable 1.
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.107.el6.x86_64
(gdb) trace main
Tracepoint 1 at 0x400541: file a.c, line 12.
(gdb) actions 1
collect $regs
end
(gdb) tstart
(gdb) break 15
Breakpoint 2 at 0x40055f: file a.c, line 15.
Breakpoint 2, main (argc=1, argv=0x7fffca819f08) at a.c:18
18 sleep (1);
(gdb) cont
Continuing.
(gdb) tstop
(gdb) tfind
Found trace frame 0, tracepoint 1
12 c = 2;
I suppose you expected tracepoint to be in actual main declaration line in the source file, am I wrong?
The important part is that it is placed in function's entry point, this is, actually, first function's code line that, looking at the information you provided, it should be c = 2;
On the other hand, this is just a stupid detail, please note that you have no code at line 15 and breakpoint has been set at line 18.
Edit:
According to your comments, you expected tfind to dump all collected registers but you would need an extra step for this: by using tfind with no argument you selected next tracepoint (first one in this case) and, to dump this tracepoint's action collected info, you should call tdump
I am using gdb to debug a fortran90 program, myprog.f90, that uses some modules, say mod1 and mod2.
I launch gdb...
$ gdb ./program
and try to set a line break...
(gdb) break 80
but I receive the error "No line 80 in file 'mod1.f90'".
So although I am trying to set a line break in myprog.f90, it's trying to set the line break in the first module of the program mod1.
How do I break a line in and step through myprog.f90?
Thank you.
Do this:
(gdb) break myprog.f90:80
See also documentation on setting breakpoints, and on location specification.
I have just moved from Ubuntu 10.04 to the new version of 11.04 and when I try to debug with ddd/gdb I cannot set anymore breakpoints nor see the flow while the debugger is executing my program.
I receive error messages saying
(gdb)b MyFile.cpp:27
No line 27 in file "MyFile.cpp".
When I start running my application calling r I also can see the following text message that looks to me related to my issue. The debuggers traps all assertions but I cannot stop at any point.
(gdb) r
BFD: /lib/x86_64-linux-gnu/libc.so.6: invalid relocation type 37
BFD: BFD (GNU Binutils) 2.18.50.20080226 assertion fail elf64-x86-64.c:278
BFD: /lib/x86_64-linux-gnu/libc.so.6: invalid relocation type 37
BFD: BFD (GNU Binutils) 2.18.50.20080226 assertion fail elf64-x86-64.c:278
If I want to see the file, the debuggers open the file with me but I receive the following error message
(gdb) list MyFile.cpp:27
Line number 27 is out of range for "MyFile.cpp".
Can you help me?
I read some forum asking to check the result of info source and info sources and this is what I have but I don't know what to do with it.
(gdb) list MyFile.cpp:27
Line number 27 is out of range for "MyFile.cpp".
(gdb) info source
Current source file is /usr/local/include/boost/exception/exception.hpp
Compilation directory is /home/emanueler/trunk/tools/myAppBinary
Located in /usr/local/include/boost/exception/exception.hpp
Contains 436 lines.
Source language is c++.
Compiled with unknown debugging format.
Includes preprocessor macro info.
Why it says "Compiled with unknown debugging format." when I am giving the -g option at compiler?
It seems all the compiling related tools were also updated, including GCC. It would be best if you recompile your entire application in this new environment before trying to debug it again.
You can do a simple test for check that your toolchain is ok. Write a small hello world app, compile it with -g and try to set a breakpoint on the cout line.