ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have installed Eclipse, Netbeans and Data Display debugger but cannot seem to get any of them to step through the source.
The source files are in a subdirectory called 'src'.
There is a directory called "examples" which has a number of c source files. Theses files have a "main" function which calls the source files in the "src' directory. One such is called "test" which takes as an argument the file name of a drawing file. I can run "./test example.dwg" from the command line.
How do I get the debugger to run the executable and pass it the path to the drawing file?
Netbeans appears to need an executable to be selected but "test" does not appear in the "Browse Executable" selection dialog which lists "Elf Executable Files".
Eclipse says "Launch failed. Binary not found."
DDD (Data Display Debugger) needs for a Program to be opened but does not show any any of the files in the examples directory as Executables.
If anyone has any suggestions, they would be appreciated.
As suggestions go, I find that one highly insulting.
You think I haven't googled extensively?
I have mentioned 3 applications that I have used to try to solve this, do you really think that I wouldn't have bothered to find out how to use them before posting a question on here?
Moreover, the link you provide is a collection of 404s and man pages, none of which appears to be relevant.
If you are trying to suggest that I use the -g switch when compiling why don't you say so, rather than be sarcastic? I have compiled using ./configure CFLAGS=-g which I believe is the equivalent.
I have tried to compile the test.c from the command line as obliquely alluded to by Mr. Steshenko using:
Code:
gcc -g -Wall test.c -o test
in the hope that this might produce an executable which may be recognised by a step-through debugger, but this generates more problems, namely that the functions referenced in test.c are defined in ../src/ so I get an error "undefined reference to `dwg_read_file'".
Using the normal method when one compiles using the ./configure && make method, the Make file will define where these library functions are located. How do I do this from the command line?
Google turns up the technique to add standard library functions using the -l switch, but I can't see any way to show the compiler that the referenced function is in a C code file in the ../src/ directory.
I do not use Eclipse, Netbeans or DDD, so I can't suggest anything about them. But here is how to run simple test program within GDB.
First, compile the library as suggested by README file.
Code:
$ sh autogen.sh
$ ./configure --enable-trace
$ make
Now we have a compiled library in src/.libs directory. There are static (*.a) and dynamic (*.so) versions. To debug the library we need a test program, for example examples/test.c. To compile it with the static version of the library:
(-static is optional) if you already installed the library (with sudo make install).
Now launch the debugger and run test program with example.dwg as an argument:
Code:
$ gdb ./a.out
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /tmp/libredwg/examples/a.out...done.
(gdb) break main
Breakpoint 1 at 0x4012de: file test.c, line 31.
(gdb) run example.dwg
Starting program: /tmp/libredwg/examples/a.out example.dwg
Breakpoint 1, main (argc=2, argv=0x7fffffffe098) at test.c:31
31 REQUIRE_INPUT_FILE_ARG (argc);
(gdb) list
26 test_dwg_c(char *filename);
27
28 int
29 main(int argc, char *argv[])
30 {
31 REQUIRE_INPUT_FILE_ARG (argc);
32 return test_dwg_c (argv[1]);
33 }
34
35 int
(gdb) step
32 return test_dwg_c (argv[1]);
(gdb)
test_dwg_c (filename=0x7fffffffe3c9 "example.dwg") at test.c:37
37 {
(gdb) l
32 return test_dwg_c (argv[1]);
33 }
34
35 int
36 test_dwg_c(char *filename)
37 {
38 int error;
39 Dwg_Data dwg_struct;
40
41 error = dwg_read_file(filename, &dwg_struct);
(gdb) s
41 error = dwg_read_file(filename, &dwg_struct);
(gdb)
dwg_read_file (filename=0x7fffffffe3c9 "example.dwg", dwg_data=0x7fffffffd460) at dwg.c:39
39 {
(gdb)
46 if (stat(filename, &attrib))
(gdb) next
49 return -1;
(gdb)
46 if (stat(filename, &attrib))
(gdb)
51 if (!S_ISREG (attrib.st_mode))
(gdb)
56 fp = fopen(filename, "rb");
(gdb)
57 if (!fp)
(gdb)
56 fp = fopen(filename, "rb");
That is it. DDD is a graphical frontend to GDB so you may use the same commands.
I set the breakpoint: break decode_r2007.c:419
when I run the program it stops at 420. I'd expect it to stop at 419, but it's no train smash.
Code:
gdb ./a.out
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/dave/Documents/Projects/Programs/workspace/libredwg/examples/a.out...done.
(gdb) break decode_r2007.c:419
Breakpoint 1 at 0x42f61f: file decode_r2007.c, line 419.
(gdb) run 4m2.dwg
Starting program: /home/dave/Documents/Projects/Programs/workspace/libredwg/examples/a.out 4m2.dwg
Breakpoint 1, decompress_r2007 (dst=0x7fffffffd960 "", dst_size=272,
src=0x7096b0 " ", src_size=166) at decode_r2007.c:420
420 uint32_t offset = 0;
(gdb)
I'm interested in getting the contents of the array src, which, I know is [32,0,0,2,0,112,96,3,10,27,128,...]
Once I wrote (for learning purposes) a tool (script) which unrolls all loops in FFT and does other optimizations.
One of the versions of the tool did it right from the point of view of final result, but sub-optimally from the point of view of generated code - there were too many occasions of the same expression calculated twice.
Surprisingly, 'gcc' optimized out about 40% of lines (!).
I wasn't running a debugger, I was looking at assembly listing with source code as comments (see, for example, http://www.fclose.com/b/programming/...ing-using-gcc/ ). Assembly listing with source code as comments should be the source of your expectations regarding stepping through code.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.