3

Ubuntu 16.04.4 LTS, GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1

I am trying to call a function in a compiled C program and get the following:

"(gdb) call getVarName(someParam)
 You can't do that without a process to debug."

There are no other codes or messages.

I can run the program from the shell prompt jef@ubuntu$ ./program. I can run the program within gdb after designating the file. Permissions are 777 (just to cover all bases).

Based on research, I set the SHELL with "export SHELL=/bin/bash" and set kernal.yama.ptrace_scope = 0 in /etc/sysctl.d/10-ptrace.conf

I still get the same behavior.

user1660886
  • 69
  • 1
  • 2
  • 8

1 Answers1

3

I still get the same behavior.

Naturally.

The error you are getting means: you can't do this, unless you are debugging a live process.

This will work:

(gdb) break main
(gdb) run
... GDB is now stopped, *and* you have a live process.
... you *can* call getVarName(...) now
(gdb) call getVarName(...)

(gdb) continue  # causes the process to run to end and exit
[Inferior 1 (process 195969) exited normally]

(gdb)  # Now you no longer have a live process, so you *again* can't
       # call functions in it.
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Yes, that worked. Thanks!! It makes sense now that I am out of the weeds and tunnel vision. I thought I could just call a function, but upon reflection what is the point of a break if that was possible... Now I get why there are a lot of forum posts with this error around core files. – user1660886 Apr 06 '18 at 16:43
  • I have a question related to this one. I'm debugging `core dump` with gdb and tried to do `print errno` to get the error code. I got `You can't do that without a process to debug`. Can you suggest some idea about why isn't it possible to print `errno`? – St.Antario Jan 19 '19 at 07:09
  • 1
    @St.Antario That's a completely separate question. Please ask one, it doesn't cost you anything. – Employed Russian Jan 19 '19 at 07:23