User forums > Using Code::Blocks

Variables <optimized out>

(1/1)

jury:
I need to debug one project so I switched off O2 compiler option from "Project -> Build options -> Compiler settings" (I do not have this option set in global settings) Nothing more is set there besides "-g" option.
Then the project was fully rebuild, but when debugging most of the variables are still <optimized out>
What do I have to do to unoptimize out my variables?

Code::Blocks 20.03 PCLinuxOS

jury:
Even thou I have unchecked the O2 from "Project -> Build Options -> Compiler settings" it still found it in .cbp file. So I manually removed it from there and rebuild the project.
But no changes, most variables <optimized out>
So I added -O0 to the other compiler options and rebuild the project again. In build log I see that -O0 was added to the compile command fine, but in debugger I still see <optimized out>
Any clues are welcomed.

BlueHazzard:
it is possible that the compiler "optimizes" variables to registers and so they are invisible for the debugger and it is possible that the compiler does this even with -g..

I suspect it is a quite easy code? Can you show a code example?
Can you post the build log from the build log tab?
Can you enable full debug logging in settings->debugger->common->full debug log and post the output from the debug log tab?


--- Quote ---Even thou I have unchecked the O2 from "Project -> Build Options -> Compiler settings" it still found it in .cbp file. So I manually removed it from there and rebuild the project.
--- End quote ---
On the left you can select the build target (debug or release) you have to remove it from the debug target, and before compiling activate the debug target from the drop down menu near the compile button in the toolbar. It can stay in the release target.

jury:

--- Quote from: BlueHazzard on December 12, 2022, 09:19:06 pm ---I suspect it is a quite easy code? Can you show a code example?

--- End quote ---

Well, at least for me its definitely not simple code. Its an open source remake of Abuse game. Code sample at the end of the post (its the function I wanted to debug)


--- Quote from: BlueHazzard on December 12, 2022, 09:19:06 pm ---Can you post the build log from the build log tab?
Can you enable full debug logging in settings->debugger->common->full debug log and post the output from the debug log tab?

--- End quote ---

Its not possible now. Yesterday I gave up with code::blocks and fired up gdb (with the binary built up by code::blocks) And all the variables were visible fine.
And today I needed to debug another piece of code and having code::blocks still open I forgot about its debugging strangeness so I fired debugger again. This time I can see the variables.

But if the strangeness comes back, I will post the full logs.
Thanks




--- Code: ---nfs_file::nfs_file(char const *filename, char const *mode)
{
  local=NULL;
  nfs_fd=-1;

  int local_only=0;
  char const *s=mode;
  for (; *s; s++)    // check to see if writeable file, if so don't go through nfs
    if (*s=='w' || *s=='W' || *s=='a' || *s=='A')
      local_only=1;

  char name[256], *c;
  char const *f = filename;
  c = name;
  while (*f) { *c=*(f++); *c=toupper(*c); c++; } *c=0;
  if (strstr(name,"REGISTER"))
    local_only=1;

  if (net_crcs && !local_only)
  {
    int fail1,fail2,fail3=0;
    char const *local_filename = filename;
    if (filename[0]=='/' && filename[1]=='/')
    { local_filename+=2;
      while (*local_filename && *local_filename!='/') local_filename++;
      local_filename++;
    }

    int remote_file_num=net_crcs->get_filenumber(local_filename);
    uint32_t remote_crc=net_crcs->get_crc(remote_file_num,fail2);
    if (!fail2)
    {
      int local_file_num=crc_manager.get_filenumber(local_filename);
      uint32_t local_crc=crc_manager.get_crc(local_file_num,fail1);
      if (fail1)
      {
    bFILE *fp=new jFILE(local_filename,"rb");
    if (!fp->open_failure())
    {
      local_crc=crc_file(fp);
      crc_manager.set_crc(local_file_num,local_crc);
    } else fail3=1;
    delete fp;
      }

      if (!fail3)
      {
    if (local_crc==remote_crc)
          local_only=1;
      }
    }
  }

  local_only = 1;

  if (local_only)
  {
    local=new jFILE(filename,mode);
    if (local->open_failure()) { delete local; local=NULL; }
  }
  else
  {


    char nm[256];
    strcpy(nm,filename);
    nfs_fd=NF_open_file(nm,mode);
    if (nfs_fd==-2)
    {
      local=new jFILE(nm,mode);
      if (local->open_failure()) { delete local; local=NULL; }
      nfs_fd=-1;
    }
  }
}
--- End code ---




Edit:


--- Quote from: jury on December 12, 2022, 10:35:28 pm ---Its not possible now. Yesterday I gave up with code::blocks and fired up gdb (with the binary built up by code::blocks) And all the variables were visible fine.
And today I needed to debug another piece of code and having code::blocks still open I forgot about its debugging strangeness so I fired debugger again. This time I can see the variables.

--- End quote ---

Well, its not that it magically started debugging in code::blocks. I tried to debug exactly the same function I did the first time and I still see <optimized out> for most variables, but the same binary debugs fine in gdb. I give up on this and will use gdb for those functions that do not show variables in code::blocks.

BlueHazzard:
It would still be nice if you could post a full rebuild log and the debugger log so we can try to fix it....

Navigation

[0] Message Index

Go to full version