Recent

Author Topic: FpDebug watch array[0..n] of char  (Read 2021 times)

440bx

  • Hero Member
  • *****
  • Posts: 4013
FpDebug watch array[0..n] of char
« on: February 27, 2024, 12:00:34 pm »
Hello,

when watching an array of char, e.g:
Code: Pascal  [Select][+][-]
  1. var
  2.   test_name : packed array[0..511] of char;
the watch window shows every character delimited by a single quote and separated by a comma.  This results in a lot of space used by quotes and commas.

Is there a way to have the (null terminated) character array be displayed showing only the characters ? that is, without any single quotes and commas.

Thank you for your help.

PS: attached is an example showing all the quotes and commas.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9846
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug watch array[0..n] of char
« Reply #1 on: February 27, 2024, 12:20:54 pm »
Not really, but kind of....

Btw, good idea for https://forum.lazarus.freepascal.org/index.php/topic,66143.0.html

The following work for me in 3.1 (fixes) / probably release too.
Code: Text  [Select][+][-]
  1. @test_name[0]
Code: Text  [Select][+][-]
  1. ^char(@test_name)
Code: Text  [Select][+][-]
  1. ^char(@test_name[0])



--- EDIT

Code: Pascal  [Select][+][-]
  1.  that is, without any single quotes and commas.
Well there will be a quote at the very start and end.

And if there are unprintable chars #1..#31 then there will be more. Same as in a Pascal source file.
« Last Edit: February 27, 2024, 12:26:14 pm by Martin_fr »

440bx

  • Hero Member
  • *****
  • Posts: 4013
Re: FpDebug watch array[0..n] of char
« Reply #2 on: February 27, 2024, 12:29:00 pm »
Those work great :)  Thank you!

Question: do you want me to post this question/request as a suggestion in the thread you linked to ?  I'll be glad to, if you'd like the idea to be mentioned in that thread.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9846
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug watch array[0..n] of char
« Reply #3 on: February 27, 2024, 12:45:22 pm »
Might be a good idea to post it there. Not sure how soon I get to it.  (I am in the middle of some display format work, but this came to late... / and the align isn't yet in there neither)

Currently I can only think of one (or two) applications.

- "array of char" => Display as string
- "string" => display as array. (e.g. decimal, hex values)

Technically an array of byte could be casted... Even an array of "number" could be a list of unicode codepoints... Not sure though.

440bx

  • Hero Member
  • *****
  • Posts: 4013
Re: FpDebug watch array[0..n] of char
« Reply #4 on: February 27, 2024, 12:49:19 pm »
Might be a good idea to post it there. Not sure how soon I get to it. 
Will do and no rush.  The suggestions you made work quite well.  I just think it would be nice if that way of displaying the null terminated arrays was the default, i.e, no user action/typecast required to obtain that format.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9846
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug watch array[0..n] of char
« Reply #5 on: February 27, 2024, 01:07:30 pm »
Also, there are 2 ways of doing that (other than the typecast).

1) A display-format (as in the watches properties, and hopefully soon also global default): "Array as string"
   (Which will only act, if the array elements are char /widechar)

2) A value formatter https://forum.lazarus.freepascal.org/index.php/topic,66186.0.html which can be configured by criteria such as the typename.

I am inclined towards the first. Unless there are good reasons why the 2nd would be better.

Not yet sure if a displayformat should cut off the trailing #0 => but it could add them as: #0 {repeated 10 times}
« Last Edit: February 27, 2024, 01:11:38 pm by Martin_fr »

440bx

  • Hero Member
  • *****
  • Posts: 4013
Re: FpDebug watch array[0..n] of char
« Reply #6 on: February 27, 2024, 01:39:33 pm »
I like the "array as string" option... I think it's intuitive and makes sense.

I think including the #0 once is useful. the (repeated 10 times) could be a source of confusion because the expected number of repetitions might be greater than that.

What I'd like to see is a way to display the null terminated array as a hex dump , defaulting to 256 (?) bytes (or some other number.) Something like "array as hex dump".

Currently with @test_name[0], changing the properties->style from default to "memory dump" causes a message "cannot read memory for expression", it would be nice if instead it showed 256 (?) hex bytes found at the address of the array, i.e, the array in hex.  It would be great if that option was available for any variable being watched.  It would provide a quick and easy way of switching from hex to type-formatted display.  While I'm dreaming, it would be absolutely great to be able to right click and toggle from "formatted" to "hex dump" for any variable being watched.  The "formatted" view would be based on the type specified in the properties.

Thanks again for the @test_name[0] suggestion, it works great... made my day :)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9846
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug watch array[0..n] of char
« Reply #7 on: February 27, 2024, 02:47:27 pm »
What I'd like to see is a way to display the null terminated array as a hex dump , defaulting to 256 (?) bytes (or some other number.) Something like "array as hex dump".

Currently with @test_name[0], changing the properties->style from default to "memory dump" causes a message "cannot read memory for expression", it would be nice if instead it showed 256 (?) hex bytes found at the address of the array, i.e, the array in hex.  It would be great if that option was available for any variable being watched.  It would provide a quick and easy way of switching from hex to type-formatted display.  While I'm dreaming, it would be absolutely great to be able to right click and toggle from "formatted" to "hex dump" for any variable being watched.  The "formatted" view would be based on the type specified in the properties.


"@test_name[0]" is a pointer, the pointer itself is not in memory (only the pointed to data).

If you have a PChar and are viewing it as data, then FPDebug handles the special case and finds the 0 terminated end (within a limit).
However if you display this a mem-dump, it wants to display the actual value (which is the pointer and that is not in memory).

You can memdump "test_name", but it will include the repeated #0 at the end. You can use repeat count...

Also (not sure if that currently works) => the chars in the array should be display-format-able (if not yet, then soon). Then you can force them as number/ord, instead of char (again, if not yet, then soon / that is part of my current change in progress). Though as array they are comma separated. As hex dump they are not.

---------------------
mem dump is avail for any variable, if the value of that variable is in memory.

If you enter "100" as watch, the debugger-backend will deliver the value 100. And the frontend can show it has hex, or bin. But the frontend does not know what that variable looks as mem dump. Neither does the backend (though the backend could be taught to create a dummy dump if the type is known / without type the size isn't known).

The frontend does not know how types are laid out in memory. E.g. a packed and non packed record...

So mem-dump is producing its own result data, and therefore must be requested from the backend. And the backend only supports that, if it actually is data that is in memory.

This matters for "debug history". Since this is stored data, no further data can be retrieved.

----------------------
However, the frontend should (if not yet, then soon) be able to display all numbers (in any array or struct) in any one chosen display format.

Mind, that is all: Using FpDebug based backends.

-----------------------

As for shortcuts (toggle memdump) in the context menu => mention in the other thread. Though the question then is which settings should have shortcuts, and why others not (all, will be to many)

440bx

  • Hero Member
  • *****
  • Posts: 4013
Re: FpDebug watch array[0..n] of char
« Reply #8 on: February 27, 2024, 09:20:51 pm »
"@test_name[0]" is a pointer, the pointer itself is not in memory (only the pointed to data).

If you have a PChar and are viewing it as data, then FPDebug handles the special case and finds the 0 terminated end (within a limit).
However if you display this a mem-dump, it wants to display the actual value (which is the pointer and that is not in memory).
yes, that's right.  What I'd like is a very quick way of telling FpDebug that I want to see a hex byte dump of what is at that address (ideally a quick toggle.)  Unfortunately, specifying "memory dump" changes the interpretation of the address.  I'd like to have that option for any type (2 bytes for a word, 4 bytes for a dword and so on, basically "n" bytes depending on the data type found at that address.  That would be great.)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9846
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug watch array[0..n] of char
« Reply #9 on: February 27, 2024, 09:47:40 pm »
For now, you can add the same watch twice. Then it can be once data, and once mem-dump. Of course, it occupies more space in the watch window (you can re-order using drag and drop).

While I am not against a quick shortcut, the trouble I have is that likely everyone will want a different choice of shortcuts:
- data vs memdump
- decimal vs binary
- structures at diff detail level (I am currently adding more display formats)
- enum as name, number or both
- ...

So there is a careful selection process that will be needed.

Maybe toggle between the last 2 settings.... That still means, once per watch you would have to go the long way.


440bx

  • Hero Member
  • *****
  • Posts: 4013
Re: FpDebug watch array[0..n] of char
« Reply #10 on: February 27, 2024, 10:16:03 pm »
While I am not against a quick shortcut, the trouble I have is that likely everyone will want a different choice of shortcuts:
You have point there.  I'm very inclined towards asm/hex but not everyone is.

The idea of having the variable twice in the watch window, once for each desired view, is definitely worth consideration.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9846
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug watch array[0..n] of char
« Reply #11 on: February 28, 2024, 07:55:50 pm »
Maybe one step closer to some of your needs to view hex data....

Though not in this case, because you still need
- the pchar watch for the string
- the array watch for other views

But, you can now (in Lazarus 3.99) chose from additional display-formats, and they do get applied to nested values.
That is, you can set a display format for the kind of data in your array (e.g. int or char) and it gets applied to the elements in the array. (same for values in structures).

In the image is your test_array, but with chars forced to hex numbers (note, it does not work for chars in a string).



440bx

  • Hero Member
  • *****
  • Posts: 4013
Re: FpDebug watch array[0..n] of char
« Reply #12 on: February 28, 2024, 08:00:15 pm »
But, you can now (in Lazarus 3.99) chose from additional display-formats, and they do get applied to nested values.
You just gave me one heck of a good reason to use Lazarus v3.99

I see another Lazarus installation in my future ;)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9846
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug watch array[0..n] of char
« Reply #13 on: February 28, 2024, 08:11:28 pm »
If all goes to plan, there will be configurable defaults too. So you can go to Tools>Options and set up what should be used for the "default" radios.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9846
  • Debugger - SynEdit - and more
    • wiki
Re: FpDebug watch array[0..n] of char
« Reply #14 on: March 01, 2024, 06:08:38 pm »
And you can now set default (IDE-global or per-project) for the watch-display-format. (except mem-dump, which technically is not a display-format, but a way to retrieve data).

You can set defaults for locals, and hints too. So you can make them show values as you want.
Individual settings for each local aren't there (yet).

The configured values are used, whenever the radio-button is on a "default", it looks for the first explicit setting in the order
project-watches (or other window)
project-global
IDE-watches (or other window)
IDE-global

If any of them has an explicit setting, you can't force that back to "default" (e.g. signed/unsigned, default depends on dec/hex/bin)

 

TinyPortal © 2005-2018