# Anyway to debug

This topic is 2860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey,

I have a program, that crashes with:
Program received signal SIGILL, Illegal instruction.

And I have not Idea of how to debug the problem. I fired up gdb, the error occurs on this line:

thinking=false;

"thinking" is a perfectly fine (member)variable of type bool.
- *this seems to fine and initialized corretctly.
- The stack backtrace seem also to be fine.

I know, you can not debug my problem. But I was wondering if anyone has any hint on how to find out more about a problem like this.

Thanks!
Nathan

##### Share on other sites
If I had to make a guess I'd say you were overrunning a buffer somewhere. Overwriting the assignment with something garbage. Are you using char*'s? Are you manually futzing about with arrays and the such?

Quick visual inspection is probably enough for that sort of thing depending on the die of your code.

##### Share on other sites
Quote:
 Original post by LonelyStarHey,I have a program, that crashes with:Program received signal SIGILL, Illegal instruction.And I have not Idea of how to debug the problem. I fired up gdb, the error occurs on this line: thinking=false;"thinking" is a perfectly fine (member)variable of type bool.- *this seems to fine and initialized corretctly.- The stack backtrace seem also to be fine.I know, you can not debug my problem. But I was wondering if anyone has any hint on how to find out more about a problem like this.Thanks!Nathan

if you use gdb, just make breakpoint somewhere where variable thinking is still valid and add watch to it.
gdb stops everytime watched variable is changed, it should do that even if someone is overwritting its memory locaction.

##### Share on other sites
Elaborating on Telastyn's answer: I would look at the binary code corresponding to that assignment when the program is loaded, and look at it again when the crash happens. Chances are it has been modified. Perhaps you can get the debugger to tell you when the modification happened (I think some incantation involving awatch in gdb can do that for you).

##### Share on other sites
It may also be that somehow you're using a class instance that doesn't exist anymore. When the crash occurs, can you check that the instance doing that member assignment is a valid instance of the class?

##### Share on other sites
Hey guys,

Thanks for all the answers.
I ran the program through valgrind. If it would change its own code, there must be an invalid write somewhere, or not?

There is non!
- How can I look at binary code corresponding to the assignment? Sounds like a great idea, but how do I do that?
- I can type *this and get a valid answer. Does this ensure, that the current instance exists/is valid? If not, how can I check it?

##### Share on other sites
If you are running function f, type the following in the gdb prompt:
(gdb) disassemble f

That should be useful.

##### Share on other sites
First of all, is this single threaded?

I have not much experience with gdb, but some debuggers misses one line. Though if this is a small function, i doubt posting it is that much helpful. I think the problem is somewhere else.

Illegal instruction very much points to data (within code segment) being modified. Unless the compiler generates bad code, which is _very_ unlikely.

But I think you can set a breakpoint for memory changes, like Alvaro described. I'm sure you'll catch that bugger :)

• 10
• 18
• 14
• 18
• 15