User forums > Using Code::Blocks

[Solved] Watches: Further expansion of structs

(1/2) > >>

stuarte:
Hi,

I searched the forum and found "Watches Expansion of structures" but that did not supply a solution to my current problem.

Basically I have not yet found out how to display the field contents in the second and further structs in a block of structs.
I have entered the variable name of a struct variable in the leftmost/bottommost field of the Watches window, right-clicked on the field and selected dereference pointer. I have also (left)clicked on the rightward pointing small black arrowhead which has displayed the field contents of the first struct in the block of structs. However I am at a loss as to how to display the field contents of the second and subsequent structs in the Watches window. For example, at the appropriate point, the Watches window shows that two records (i.e. structs) have been created but the Watches window still shows the field contents of the first struct. Could you please advise how to get the Watches window to display the field contents in the second and further structs ?

Above main() I have :-


--- Code: ---typedef struct rec
{
   char recordUsed;
   char firstName[15];
   char lastName[15];
   char phoneNumber[15];
} record;

--- End code ---

To grab a block of memory I use:-


--- Code: ---static record * createRecords(unsigned int * ptrRecordsCreated)
{
   record * ptrRecords;
   size_t numberOfRecords = 5;
   size_t index;

   ptrRecords = calloc(numberOfRecords, sizeof(record));
   if (ptrRecords == NULL)   /* if memory not available ... */
   {
      printf("\nERROR! Out of memory!\n");
      printf("\nExiting program\n");
      exit (0);           /* ... exit program */
   }

   /* Mark all records as not used */
   for (index = 0; index < numberOfRecords; index++)
   {
      ptrRecords[index].recordUsed = 'N';
   }

   *ptrRecordsCreated += numberOfRecords;
   return ptrRecords;
}  /* end createRecord() */

--- End code ---

AndrewCot:
Can you let us know the following so I can have a look at it tomorrow if I get time:

* C::B version you are using?
* GDB version you are using?
* Compiler and version used.
* Compiler options used.
* OS & version used
* Can you attach a debug log of the program being run including when you expand the variable with Settings->Debugger->Common setting for 'Full (debug) log" ticked as it then shown a bunch more info in the debugger log output. Zip up the log as it can get big.All of these can/may/will affect the ability to debug or how debugging works.  For example GDB 8.1 has issues and some GCC version's still run some optimize passes even with -Og  enabled.
If you have time could I also get a small project and source to save me time setting up a program to test with the latest C::B and GCC 12.1 and GDB 12.1 on Windows? I can also test on Xubunu 22.04 or LM 21.0.

stuarte:
Hi Andrew,

Here is the data requested:

1. C::B version you are using?     20.03 build 2020-04-18, 19:47:24 - wx3.0.4 - gcc 9.3.0 (Linux, unicode) - 64 bit
2. GDB version you are using?       9.2-0ubuntu1-20.04.1      **(according to Synaptic)
3. Compiler and version used.     GCC 4:9.3.0-1ubuntu2        **(according to Synaptic)
4. Compiler options used.           None.
5. OS & version used                  Kubuntu 20.04.1 (continuously updated!)
6. Settings->Dubugger->Common already/always set to "Full (debug) log".

How do I copy the contents of "Logs & others" window, Debugger tab to a text editor, or can this log be found in a particular place ?

How do I attach my current project to a forum reply ?
I tried using the forum attachments tool to attach the project folder but when I clicked on "Open" it merely opened the project folder.

Stuart

stuarte:
Hi Andrew,

Please find attached file CB_Full_Log.txt.

Stuart

AndrewCot:
I would advise:

* Update your GCC compiler if you can.
* Update your GDB if you can.
* Update C::B to the latest nightly (see https://forums.codeblocks.org/index.php/board,20.0.html forum)After adding the pointer to the watch window do the following:
* Select the variable by clicking once on the row
* Right click and select the "properties" in the pop up context menu
* In the array group do the following:
* check the [X] Watch as array
* Enter the number of elements in the struct as the Count
* Now the pointer to the struct will be shown as an array of the count you entered
* You can now expand each element to see the data.

Navigation

[0] Message Index

[#] Next page

Go to full version