Author Topic: debugging  (Read 4364 times)

Offline kateausten

  • Multiple posting newcomer
  • *
  • Posts: 19
debugging
« on: April 25, 2010, 09:14:03 am »
Hello,

I'm new to codeblocks and I'm learning how to debug.
I am facing some problems :
- how can I watch the fields of a structure that is an element of an array ?
I managed to show the elements of the array, but there are just memory addresses and I'd like to access these addresses to show its fields.
- is it possible to debug a gui application, and if it is then how ?

Thanks

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: debugging
« Reply #1 on: April 25, 2010, 04:03:32 pm »
Hello,

I'm new to codeblocks and I'm learning how to debug.
I am facing some problems :
- how can I watch the fields of a structure that is an element of an array ?

Have you tried to add: my_array[0] in the watches window?
If the variable is int**my_array[5], you can use *my_array[3]...

I managed to show the elements of the array, but there are just memory addresses and I'd like to access these addresses to show its fields.
- is it possible to debug a gui application, and if it is then how ?

A GUI app is the same (on win32 it's almost the same) as console app, so there is no difference in the way one debugs it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline kateausten

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: debugging
« Reply #2 on: April 25, 2010, 08:41:16 pm »
I'm sorry I don't understand how it is the same.
Would you mind explaining to me how to debug a GUI then ?
I'm trying to debug a SDL application. The process terminates with status 3 when I click on a specific item.
Hence I added a breakpoint to the line saying "case SDL_MOUSEBUTTONUP:" (= if a mouse click has been detected).
When I click on debug/continue (to start the debugger), the application opens and I see it in the task bar but I can't see its contents (it is reduced and I can't restore it).

I'm using svn 6088.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: debugging
« Reply #3 on: April 25, 2010, 10:02:24 pm »
Hm, a GUI app is the same thing as a non GUI app, both are C/C++ applications.
The difference is only in the used frameworks.

If your app crashes, the debugger should catch it and break on the line of the crash.
If this is not happening there is something wrong in your setup.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline kateausten

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: debugging
« Reply #4 on: April 25, 2010, 10:52:06 pm »
okay, I believe you... can you help me to figure out what's wrong in my setup then?
I must say that I have no problem debugging console applications though.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: debugging
« Reply #5 on: April 25, 2010, 11:21:46 pm »
Does your app reaches the beginning of the main function (put a breakpoint on the first line)?

There is a chance that when run the executable couldn't find all needed dlls.
Also does it start with the run button?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline kateausten

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: debugging
« Reply #6 on: April 25, 2010, 11:58:32 pm »
When executed with the run button, the application opens normally.
As I said, it's only when I click on a specific button with my mouse that the application crashes.
If I click on debug/continue without any breakpoints, the application opens normally but I can't click on anything but 'stop debugger' (next line, for instance, is grey).
This is very weird, it seems I have to press on 'stop debugger' twice to make it stop.
I'm awaiting your help because I really don't know what's going on.
« Last Edit: April 26, 2010, 12:04:13 am by kateausten »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: debugging
« Reply #7 on: April 26, 2010, 12:28:16 am »
Stop button usage:
1. first click/press = pause debuggee (debugged executable)
2. second click/press = stop debugging session

The step/next buttons are active only when the debugger is in paused mode:
1. with the stop button
2. when a breakpoint is hit
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline kateausten

  • Multiple posting newcomer
  • *
  • Posts: 19
Re: debugging
« Reply #8 on: April 26, 2010, 01:11:56 am »
hmm...
So how can I basically see what makes my program freeze/stop unexpectedly, and then fix it ?
(My program consists mainly of a while 1 loop).

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: debugging
« Reply #9 on: April 26, 2010, 12:02:39 pm »
Maybe you should start from here: http://www.whyprogramsfail.com/
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]