RedSamosaTacos
RedSamosaTacos

Reputation: 39

GDB is not working, getting [New Thread 0xf03 of process 20199] as output

GDB does not seem to be working at all for me. I compiled my program using -g option, and I am trying on very simple C program for sanity check and it is not working.

Here is the C program I am using:

#include <stdio.h>

int main(int argc, char * argv[]){

  printf("Hey");

  return 0;
}

I compiled it with this command: gcc -std=c99 -g -o test test.c

Upon running gdb this is what I get:

...
 $ gdb ./test
GNU gdb (GDB) 8.3.1
Copyright (C) 2019 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-apple-darwin18.7.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test...
Reading symbols from /Users/Braulio/Programming/C/ComputerArchitecture/floatingPoint/test.dSYM/Contents/Resources/DWARF/test...
(gdb) run
Starting program: /Users/Braulio/Programming/C/ComputerArchitecture/floatingPoint/test
[New Thread 0xd03 of process 13458]

and it just hangs here.

I was previously having issues with codesign, I followed the steps given here https://sourceware.org/gdb/wiki/PermissionsDarwin I no longer have the codesign issue.

Update

I followed user3629249 suggestions

Compiled using: $ gcc -std=c99 -ggdb3 -Wall -Wextra -Wconversion -pedantic -c test.c -o test.o

It is still hanging on [New Thread 0x1203 of process 17921]

 $ gdb test.o
GNU gdb (GDB) 8.3.1
Copyright (C) 2019 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-apple-darwin18.7.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from test.o...
(gdb) break main
Breakpoint 1 at 0xf: file test.c, line 40.
(gdb) run
Starting program: /Users/Braulio/Programming/C/ComputerArchitecture/floatingPoint/test.o
[New Thread 0x1203 of process 17921]

However this time it is only Reading symbols from one location

Upvotes: 3

Views: 2531

Answers (3)

Pedro Botsaris
Pedro Botsaris

Reputation: 21

I tried removing set startup-with-shell enable from ~/.gdbinit. It didn't work for me but it might for you, so try that first.

more about here: https://timnash.co.uk/getting-gdb-to-semi-reliably-work-on-mojave-macos/

I then set the startup-with-shell to off it and that worked.

echo "set startup-with-shell off" >> ~/.gdbinit

Upvotes: 2

user3629249
user3629249

Reputation: 16540

regarding:

gcc -std=c99 -g -o test test.c

Much better to turn on the warnings, then fix those warnings. Suggest:

gcc -std=c99 -ggdb3 -Wall -Wextra -Wconversion -pedantic -c test.c -o test.o

the options to gcc will result in displaying several problems with the OPs code that should be corrected before continuing with the link step:

the link step:

gcc -std=c99 -ggdb3 test.o  -o test

Note: the option: -ggdb3 will result in the maximum amount of debug info in the object file: test.o and needs to be used in both the compile and the link steps

one thing to notice is this statement:

printf("Hey");

probably will not display on the terminal until the program exits. This is because the output stream stdout is buffered and needs to be 'encouraged' to pass the data on to the terminal. A simple way to do this is to terminate the format string with '\n'. I.E.

printf("Hey\n");

an appropriate way to run gdb is:

gdb test
br main
run
continue

in gdb:

there is no need to indicate any 'path' (you should run gdb in the same directory as the source, object, and executable) otherwise you will need to type several more commands into gdb before typing: br main

the command: br main will set a breakpoint at the beginning of the main() function

The command: run will cause the executable to be run until the breakpoint at main()

The command: continue will cause the rest of the executable to run to completion

Upvotes: 0

David G.
David G.

Reputation: 690

The line

Reading symbols from /Users/Braulio/Programming/C/ComputerArchitecture/floatingPoint/test.dSYM/Contents/Resources/DWARF/test...

worries me. I suspect you have other things in your directory that are being implicitly accessed by GDB. I don't get that line, and it works find for me (though the lack of a newline in the output is slightly disturbing).

I find the "New Thread" notation unexpected as well.

For reference:

$ gdb ./test
GNU gdb (Debian 8.3.1-1) 8.3.1
Copyright (C) 2019 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 "arm-linux-gnueabihf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./test...
(gdb) run
Starting program: /tmp/test
Hey[Inferior 1 (process 14573) exited normally]
(gdb)

Upvotes: 1

Related Questions