Author Topic: [Solved] Watches: Further expansion of structs  (Read 1319 times)

Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 21
[Solved] Watches: Further expansion of structs
« on: September 24, 2022, 12:36:11 pm »
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;

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() */
« Last Edit: October 31, 2022, 12:48:36 pm by stuarte »

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Watches: Further expansion of structs
« Reply #1 on: September 24, 2022, 12:57:44 pm »
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.
« Last Edit: September 24, 2022, 01:00:36 pm by AndrewCot »

Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Watches: Further expansion of structs
« Reply #2 on: September 24, 2022, 02:13:38 pm »
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

Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Watches: Further expansion of structs
« Reply #3 on: September 24, 2022, 02:19:50 pm »
Hi Andrew,

Please find attached file CB_Full_Log.txt.

Stuart

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Watches: Further expansion of structs
« Reply #4 on: September 25, 2022, 02:07:42 am »
I would advise:
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.

Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Watches: Further expansion of structs
« Reply #5 on: September 27, 2022, 12:33:27 pm »
Good morning Andrew,

Quote
1. Update your GCC compiler if you can.
2. Update your GDB if you can.
3. Update C::B to the latest nightly (see https://forums.codeblocks.org/index.php/board,20.0.html forum)

First, according to Synaptics, the installed versions of both GCC and GDB are the latest versions.
Point 3. above I will hold in abeyance for the moment.

Quote
After adding the pointer to the watch window do the following:

1. Select the variable by clicking once on the row
2. Right click and select the "properties" in the pop up context window
3. In the array group do the following:

  • check the [X] Watch as array
  • Enter the number of elements in the struct as the count

I did all this. When I then ran the program in debug/single-step mode a pop up box appeared stating that "Structure has no component named operator[].". Also, in the Watches window, the line at the bottom of the window that "hosts" pointer "theseRecords" now displays that same "Structure..." message in the middle column. Finally, the little black triangle is now missing.

Stuart



Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Watches: Further expansion of structs
« Reply #6 on: September 27, 2022, 12:45:03 pm »
Hi Andrew,

Please find attached a zip file of the (as yet unfinished/needs refactoring) project, as you initially asked for. Sorry it took me so long. Just not used to making zip files on Linux.  :(

Stuart

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Watches: Further expansion of structs
« Reply #7 on: September 27, 2022, 12:55:45 pm »
The steps above worked for me with the latest GCC and GDB and C::B versions.



Offline stuarte

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: [Solved] Watches: Further expansion of structs
« Reply #8 on: October 31, 2022, 12:56:53 pm »
Good morning Andrew,

Since my last posting I have upgraded my system to Kubuntu 22.04 LTS. This has resulted in the updating both GCC and GDB. This, in turn, has cured the problem I was having with Code::Blocks, just as it did for you.

Many thanks for all(!) your help and patience(!).

Stuart