marcsosduma / cobgdb

Command-Line Debugger for GnuCOBOL on Linux and Windows
GNU General Public License v3.0
5 stars 1 forks source link

Variables with binary data #33

Open eugeniodilo opened 9 months ago

eugeniodilo commented 9 months ago

Can you explain how variables that are not of type "DISPLAY" should be read and updated from the user. For example, fields for which a value is displayed with a slash. In the following sample sScreenName is the variable, it contains a namefile followed by x'00'. What does \000 means ... or in other cases \262 etc ...

image

other sample

image

eugeniodilo commented 6 months ago

Hi MArcos, I'm writing to you just to remind of this question.

GitMensch commented 6 months ago

That's an octal representation of data, because of GDB's default (still hard-wired):

https://github.com/bminor/binutils-gdb/blob/ebf18671351d94185823d364b75369abc1baba31/gdb/valprint.c#L2157-L2175:

                  value = extract_unsigned_integer (&orig[i], width,
                                                  byte_order);
                  /* If the value fits in 3 octal digits, print it that
                     way.  Otherwise, print it as a hex escape.  */
                  if (value <= 0777)
                    {
                      xsnprintf (octal, sizeof (octal), "\\%.3o",
                                 (int) (value & 0777));
                      *need_escapep = false;
                    }
                  else
                    {
                      xsnprintf (octal, sizeof (octal), "\\x%lx", (long) value);
                      /* A hex escape might require the next character
                         to be escaped, because, unlike with octal,
                         hex escapes have no length limit.  */
                      *need_escapep = true;
                    }
                  append_string_as_wide (octal, output);

For the Vim Termdebug plugin we parse the mi result and undo the encoding; vim will then try to render the character according to LANG, if possible, otherwise escape it again for the display.

In theory, for cobgdb the data which is encoded that way could be recoded as hex.

The biggest issue is the other way around: how would you enter binary data?

eugeniodilo commented 6 months ago

I think the simplest way would be to manage all the variables both in ASCII character format and also in hexadecimal when necessary and requested by the user. Both when displaying the contents of a variable and when asking the user to type the contents of a variable. Which is the same thing that the other TUI debuggers/animators I've used in the past do. We are much more used to hexadecimal coding than to octal coding (which I have never used)