GDB ignores my breakpoints

后端 未结 3 1103
小鲜肉
小鲜肉 2021-01-17 17:36

My test case is so simple that I must be doing something very stupid. I wrote a simple source file test.c:

#include

int main(int         


        
相关标签:
3条回答
  • 2021-01-17 18:10

    (curated from comments)

    You do not appear do be doing anything wrong; It appears to be GDB's fault.

    The message During startup program exited normally. is anomalous, the correct one being Program exited normally.. It suggests GDB failed to insert a breakpoint in main() or the traced program's call to ptrace(PT_TRACE_ME, 0, 0, 0) failed. The program thus ran without being stopped, and it exited while GDB was only expecting it to start up and stop at exec(). Can you run gdb under strace while doing your example and grep strace's log for any failed ptrace calls?

    You would do so with strace -f -o syscall.txt gdb ./a.out.

    As of right now a stop-gap measure appears to be to run GDB as root.

    0 讨论(0)
  • 2021-01-17 18:13

    I had this same problem. It was intermittent and drove me nuts. Then I found I did a dumb thing. I had been running the program from the command line, and it had a bunch of arguments.

    So, I copied the command line with the mouse-copy-paste buffer.

    Then started: gdb Program

    Then did: break man

    Then did: -PASTE-FROM-MOUSE-

    It never stopped, until I realized that I had pasted too much of the command line: "--option=c ... |& tee LOG"

    It looked like an intermittent problem, until I realized it was a brain bug. Hope this helps someone. The command line redirect - did something in GDB, no clue what (other than ignore breakpoints).

    0 讨论(0)
  • 2021-01-17 18:15

    I encountered a similar problem and in my case the thing was that my program was forking itself. So basically, my code looked like this:

    #include <string>
    #include <iostream>
    #include "func.hpp"
    
    using namespace std;
    
    int main(int argc, char **argv)
    {
            if(argc <3)
            {
              printf("\n %s IP PORT\n",argv[0]);
              printf("e.g. %s 10.32.129.77 6379\n",argv[0]);
              printf("\n Going to run on the default server and port\n");
              string command{argv[0]};
              command+=" 10.32.129.77 6379";
              printf("\nCommand: %s\n",command.c_str());
              system(command.c_str());
              exit(0);
            }
    
    func();
    }
    

    I was creating a breakpoint where "func" function was being called. However, I unknowingly wasn't passing the correct arguments and as a result my program forked itself with correct arguments. So basically "func" was now being called from the child process and as it turns out gdb doesn't set the breakpoints at the child process and that's why the breakpoint was not being hit.

    0 讨论(0)
提交回复
热议问题