Home > front end >  Now output when debugging hello world in a C script with gdb on Macos (only working when both script
Now output when debugging hello world in a C script with gdb on Macos (only working when both script

Time:11-01

I installed gdb on Macos 11.2.3. I set it up following this tutorial and have currently a file .gdbinit containing set startup-with-shell off. I use the following script:

#include <stdio.h>
#include <stdlib.h>

int main (){
  printf("hello world");
  return 0;
}

Then I ran the command:

$ gcc -Wall hello_world.c -o hello_world.o
$ gdb hello_world.o
(gdb) run
...
Starting program: /path/to/hello_world.o
[New Thread 0x2403 of process 10983]

But don't get the printed hello world

Now if generate a.out with gcc hello_world.c and then run gdb hello_world.o (creating both hello_world.o and a.out) and (gdb) run now I get

$ gcc -Wall hello_world.c -o hello_world.o
$ gcc hello_world.c
$ gdb hello_world.o
...
(gdb) run
Starting program: /path/to/hello_world.o
[New Thread 0x2803 of process 15213]
[New Thread 0x1c03 of process 15213]
warning: unhandled dyld version (17)
hello world[Inferior 1 (process 15213) exited normally]

It seems that gdb works when there are both hello_world.o and a.out but not hello_world.o alone. Why? What am I doing wrong? How can I run gdb and getting the hello world output without having to compile the script with both $gcc -Wall hello_world.c -o hello_world.o and $ gcc hello_world.c

EDIT There seems to be a problem with Macos according to this github link where the following is being said:

If after hitting run in `gdb`, you get "Starting program: /path/to/your/executable [args] [New Thread 0x2303 of process 795]" followed by a blank line which does not respond to anything, then you have hit GDB bug 24069. Check that you built the patched version from source.

CodePudding user response:

What am I doing wrong?

You are trying to run hello.o, which is not an executable program, and can not run.

The tutorial you are following creates an executable with gcc hello_world.c -o hello_world -ggdb (note lack of the -c argument).

CodePudding user response:

Ok I could solve the problem following the instruction on GDB Wiki BuildingOnDarwin

  • Related