NO

Author Topic: view source code during debugging  (Read 22784 times)

vedro-compota

  • Guest
view source code during debugging
« on: May 24, 2012, 04:33:24 PM »
Hello)

guys, please tell me - how to view source code during  debugging ?
I see only puch-mov-push-mov-mov etc - but when i try to set tick near "show sourse code" (to debug through the lines) - nothing happen....
please help..........

Offline DMac

  • Member
  • *
  • Posts: 272
Re: view source code during debugging
« Reply #1 on: May 24, 2012, 05:57:06 PM »
Hello Mr. Vedro

It sounds like you are right clicking to view the disassembly while in Debug mode.

Debugging in Pelles works in three steps.

Step one Compile in debug mode. (See step 1)

Step two Set break point and click debug/go. (See step 2)

Step three Hit F10 to step through code and view values in the watch window. (See step 3)
No one cares how much you know,
until they know how much you care.

CommonTater

  • Guest
Re: view source code during debugging
« Reply #2 on: May 24, 2012, 05:59:54 PM »
Edit: I see DMac beat me to it :D
 
Since not all of us use the DBG/REL/PRF AddIn, here's how to set the options manually...
 
On the main menu...
Project -> Project options -> Compiler -> Debug information = full

Plus...
For 32 bit projects:
Project -> Project options -> Linker -> Debug information  = Code View and Coff
For 64 bit projects:
Project -> Project options -> Linker -> Debug information = Code View

Set at least one breakpoint.
Then click the Go Debug button on your toolbar.
« Last Edit: May 24, 2012, 06:03:58 PM by CommonTater »

vedro-compota

  • Guest
Re: view source code during debugging
« Reply #3 on: May 25, 2012, 12:51:47 AM »
DMac , thank you) but my IDE have different from yours buttons....but i've tuned Pelles C as CommonTater (thank you too!) said  and I can walk through the lines in debug mode, but I can understand why on several custom function Pelles C leave the source code and run through.....push-mov - assambler as I understand)

CommonTater

  • Guest
Re: view source code during debugging
« Reply #4 on: May 25, 2012, 04:43:31 AM »
DMac , thank you) but my IDE have different from yours buttons....but i've tuned Pelles C as CommonTater (thank you too!) said  and I can walk through the lines in debug mode, but I can understand why on several custom function Pelles C leave the source code and run through.....push-mov - assambler as I understand)

Because that segment of code is probably in a library or dll that does not have debugging symbols.

vedro-compota

  • Guest
Re: view source code during debugging
« Reply #5 on: May 25, 2012, 07:33:51 AM »
hm. so in this case i should debug through assembler?
because of this I was try to debug in Visual Studio - but it doesn't like lines as:
Code: [Select]
struct user
int zone;
int city;
int node;
int point;
char* name;
};
struct user  users[b]; //  [i][b]error C2057: expected constant expression[/b][/i]
users[n].name=malloc(sizeof(char));
but Pelles C doesn't worry because of  "constant expression" why it's so or may be it's difference between C and C++ ?.....


Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: view source code during debugging
« Reply #6 on: May 25, 2012, 08:08:21 AM »
hm. so in this case i should debug through assembler?
because of this I was try to debug in Visual Studio - but it doesn't like lines as:
Code: [Select]
struct user
int zone;
int city;
int node;
int point;
char* name;
};
struct user  users[b]; //  [i][b]error C2057: expected constant expression[/b][/i]
users[n].name=malloc(sizeof(char));
but Pelles C doesn't worry because of  "constant expression" why it's so or may be it's difference between C and C++ ?.....
With just that snippet, it is impossible to tell. The basic problem is that you define and array with "b" elements, with a definition of b nowhere in sight. You can't dynamically define an array like this, neither in C or C++ (FAIK), unless "b" refers to a "const" defined elsewhere in your code...

With bad programming practices, compiler/development environment behavior is random at best...

Ralf

CommonTater

  • Guest
Re: view source code during debugging
« Reply #7 on: May 25, 2012, 08:11:27 AM »
Vedro... C++ and C are two completely separate languages... they are maintained independently, each to their own separate set of standards.  It is a terrible mistake to think that because something works one way in C that C++ should play along or because something works in C++ that it should work in C too.... It just doesn't work that way.

Yes C++ compilers will compile some C code... but it's not C code at the same standards as true C.  For example, Microsoft's VC++ compiler won't compile C-99 or C-11 code... the two current C coding standards.

Also note that debugging is of no value on code that produces compile-time errors and warnings...
The compiler's warnings are about being able to build the executable.
The debugger is about finding behavoural problems in code that compiles correctly.

vedro-compota

  • Guest
Re: view source code during debugging
« Reply #8 on: May 25, 2012, 08:14:28 AM »
so - as i understand - it's incorrect to write -

Code: [Select]

struct user
int zone;
int city;
int node;
int point;
char* name;
};
n= salen(arr); // get number of str

printf("[[[ Numer of useful strings = %i ]]] \n",n);
int b=n;
struct user  users[b];
users[n].name=malloc(sizeof(char));

CommonTater

  • Guest
Re: view source code during debugging
« Reply #9 on: May 25, 2012, 08:15:58 AM »
With just that snippet, it is impossible to tell. The basic problem is that you define and array with "b" elements, with a definition of b nowhere in sight. You can't dynamically define an array like this, neither in C or C++ (FAIK), unless "b" refers to a "const" defined elsewhere in your code...

Try this....

Code: [Select]
int main (void)
  {  int c = 11;
      int array[c];

      return 0; }

C-99 and C-11 will let you define local array sizes at run time, using variables...

Quote
With bad programming practices, compiler/development environment behavior is random at best...

As it was put to me many years ago:  No program is ever better than the worst programmer who worked on it.

vedro-compota

  • Guest
Re: view source code during debugging
« Reply #10 on: May 25, 2012, 08:19:53 AM »
Quote
Try this....
Code: [Select]
int main (void)
  {  int c = 11;
      int array[c];
      return 0; }
but i need to create array dynamically!

CommonTater

  • Guest
Re: view source code during debugging
« Reply #11 on: May 25, 2012, 08:21:29 AM »
so - as i understand - it's incorrect to write -

So lets take a look....
Code: [Select]

struct user      <--- missing brace
   int zone;   
   int city;
   int node;
   int point;
   char* name;
};
n= salen(arr); // get number of str
   
   printf("[[[ Numer of useful strings = %i ]]] \n",n);
   int b=n;                                                          <-- unnecessary variable
   struct user  users[b];                                        <-- may cause stack overflow if n is too big
   users[n].name=malloc(sizeof(char));                     <-- allocates only 1 character for name storage
           

CommonTater

  • Guest
Re: view source code during debugging
« Reply #12 on: May 25, 2012, 08:22:03 AM »
Quote
Try this....
Code: [Select]
int main (void)
  {  int c = 11;
      int array[c];
      return 0; }
but i need to create array dynamically!

Then learn how to use malloc() correctly.


vedro-compota

  • Guest
Re: view source code during debugging
« Reply #13 on: May 25, 2012, 08:31:58 AM »
>>>>> users[n].name=malloc(sizeof(char));                     <-- allocates only 1 character for name storage

yes, but in that case i needed firstly to "set dot of array" - EOF in last element name - before  initialization of  others elements

>>>>>>>>>> int b=n;                                                          <-- unnecessary variable

yes - you are right --  i was try to get round exeption of "constant expression" by this stupid way))

>>>>>>>>>>struct user  users;                                      <-- may cause stack overflow if n is too big

yes , but that is my problem, as I think - because of how can i create array dynamically in other way.........

Quote
Then learn how to use malloc() correctly.
ok. i'll do as you said

vedro-compota

  • Guest
Re: view source code during debugging
« Reply #14 on: May 25, 2012, 08:34:33 AM »
Quote
how to use malloc() correctly.
malloc()? but may be calloc for array is better....ok - that's my problem - i'll solve it ........ big thanks!