0

I am using GDB to debug my C program. And since I am handling SIGUSR1 in my program. So once I run the gdb with my program executable like -

gdb <my_executable>

under the gdb prompt (gdb) I need to enter -

handle SIGUSR1 nostop noprint pass

since I need to do this every time, I wanted to place this handle command in the init script. So after googling, I got to know about the ~/.gdbrc and ~/.gdbinit. I tried to place the handle command in both the files, but still I don't see that handle command is executed once after gdb reads the symbols from the executable.

What could be wrong with this?

Edit: GNU gdb (GDB) 7.2.2

Edit 2: My .gdbrc file content looks like -

 echo "hello from gdbrc"
 handle SIGUSR1 nostop noprint pass
 run 204

Edit 3: Even I tried with GNU gdb (GDB) 8.1.3 Still I'm facing the same issue.

Edit 4: The ~/.gdbrc and ~/.gdbinit are given full access permission -

-rwxrwxrwx   1 darshan grp      68 Oct  9 22:14 .gdbint
-rwxrwxrwx   1 darshan grp      67 Oct  9 22:14 .gdbrc

Edit 5: I had named the file wrongly as ".gdbint" instead of ".gdbinit". After renaming, I found with the GDB 8.1.3, it is being read at the startup. However, with GDB 7.2.2 still I see the problem - .gdbinit file is not read at the startup.

And ~/.gdbrc is NOT a right filename to use and won't be recognized by GDB.

Darshan L
  • 824
  • 8
  • 30
  • Could you add the output of `gdb --version | head -1` to your question? – Mark Plotnick Oct 09 '20 at 13:56
  • If you add `echo done loading\n` to the end of your `~/.gdbinit` file, and run gdb again, do you see the `done loading` line? – Mark Plotnick Oct 09 '20 at 13:58
  • @MarkPlotnick I tried adding echo command inside both the files, but I don't see the print in the output. However, when I pass .gdbrc as an -X argument then I could see the output. So seems like the.gdbint / .gdbrc files are not executed at the beginning – Darshan L Oct 09 '20 at 14:08
  • Even I tried with GNU gdb (GDB) 8.1.3 Still I'm facing the same issue. – Darshan L Oct 09 '20 at 16:35
  • 1
    Your listings show `-rwxrwxrwx 1 darshan grp 68 Oct 9 22:14 .gdbint` rather than `.gdbinit`; was that just a cut and paste error? – Mark Plotnick Oct 09 '20 at 17:50
  • @MarkPlotnick You are right. My bad. I had created the file with .gdbint. After changing it to .gdbinit, with GDB version 8.1.3, it is working but not with GDB version 7.2.2. Can I assume GDB 7.2.2 didnt support .gdbinit? Another question is - what is the different purposes between ~/.gdbinit and ~/.gdbrc ? – Darshan L Oct 09 '20 at 18:10

1 Answers1

1

Can I assume GDB 7.2.2 didnt support .gdbinit?

GDB has supported reading ~/.gdbinit since forever (at least since version 4.0, but probably much earlier).

You should be able to figure out what's happening by looking at the output from

strace -e file gdb --version |& grep gdbinit

Here is what I see:

stat("/home/employedrussian/.gdbinit", {st_mode=S_IFREG|0640, st_size=629, ...}) = 0
stat(".gdbinit", 0x7ffe51ef72f0)        = -1 ENOENT (No such file or directory)

Update:

When I run the command, I see no output with GDB 7.2.2 But with GDB 8.1.3, I see the same output like you.

Ok, it seems that you have a broken version of GDB 7.2.2. Try newer version.

I could not find any bug about GDB not reading .gdbinit, but maybe it was broken at some point temporarily.


what is the different purposes between ~/.gdbinit and ~/.gdbrc

The former is read by GDB, the latter isn't (where did you get the idea that GDB would read it?).

Update:

I thought just like many other linux application

It is a UNIX shell convention to read ~/.${SHELL}rc file on startup, and may other applications do so as well. But GDB isn't one of them.

http://stackoverflow.com/a/7195718/5347487

That answer is wrong.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • > `strace -e file gdb --version |& grep gdbinit` When I run the command, I see no output with `GDB 7.2.2` But with `GDB 8.1.3`, I see the same output like you. > `The former is read by GDB, the latter isn't (where did you get the idea that GDB would read it?).` I thought just like many other linux application an *rc file would be present for GDB also and googled it and found this answer - https://stackoverflow.com/a/7195718/5347487 – Darshan L Oct 10 '20 at 07:50
  • Thanks for taking your time to look if there was any bug in gdb. I wish I could&amp;amp;#39;ve moved to newer version of GDB. But got a problem - when I try to place a breakpoint using a function name - it says, function name is not found, and asks if it is part of a shared library. But if I pretend the function name with `__be_` then it accepts the breakpoint. Not able to understand this behaviour and reason for this incompatibility. Binary is generated using ICC compiler for a x86_64 architecture. – Darshan L Oct 10 '20 at 18:05
  • I learnt today that while building GDB source code, we can pass some flags to define it's behaviour. So I was wondering could it be possible that the GDB 7.2.2 that I'm using is built with an option not to read .gdbinit file? – Darshan L Oct 11 '20 at 14:35
  • @DarshanL It's also possible to edit the source of GDB and introduce bugs. If you are using modified version of GDB, then we can't _know_ what these modifications were. You'll have to figure that out yourself. – Employed Russian Oct 11 '20 at 16:37