* * *

Author Topic: [resolved] Inspecting larger array sizes  (Read 1125 times)

daz

  • Full Member
  • ***
  • Posts: 106
    • http://matt-shaffer.com
[resolved] Inspecting larger array sizes
« on: March 19, 2018, 06:35:37 am »
Hello. I have some code which looks like the following:

Code: Pascal  [Select]
  1. readBuffer: Array of Array[0..4095] of Byte;

I add readBuffer[0] and readBuffer[1] to the watchlist.

Currently it seems the watchlist window does not show past index 40. Inspecting the value does not provide any value. If I go to Evaluate / Modify it seems to stop printing after the 2500th entry.

How should I go about debugging the value of this array if I can not view the whole thing? For instance, looking at the last 20 or so elements of the array is critical

But adding things to the watchlist such as readBuffer[0][4095] is rather tedious.
« Last Edit: March 19, 2018, 10:09:40 am by daz »

Thaddy

  • Hero Member
  • *****
  • Posts: 6099
Re: Inspecting larger array sizes
« Reply #1 on: March 19, 2018, 07:21:36 am »
Are you sure you mean a dynamic array of static array? Array of Array[0..4095] of Byte;
Instead of static array of static array? Array[0..4095] of Array[0..4095] of Byte;

I mean, without calling setlength() on the first there is no valid element array[0][0] and the debugger may not be able to work with that.

If this is not the case and the array is fully static, declare a subarray as absolute to say.. the last 10 elements and add that to the debugger instead.
Code: Pascal  [Select]
  1. // This trick is only safe for fully static arrays.
  2. // Not for dynamic arrays because these can be relocated on SetLength.
  3. program debugarray;
  4. var
  5.   A:array[0..4095] of array[0..4095] of byte;
  6. {$ifopt D+}
  7.   B:array[0..9] of byte absolute A[4095][4085];// debug proxy for the last 10 elements
  8. {$endif}
  9. begin
  10. end.
Note you can also add simply that High A[4095][4085]  address in the debugger, but I find this often easier to set up in code.

Example setups, both different approach, both work.:

« Last Edit: March 19, 2018, 09:03:17 am by Thaddy »
I might not give the answer that you want me to.. Peter Green 1969

daz

  • Full Member
  • ***
  • Posts: 106
    • http://matt-shaffer.com
Re: Inspecting larger array sizes
« Reply #2 on: March 19, 2018, 09:37:48 am »
Hi, yes I mean to have it as a dynamic array. SetLength is called. My problem is the contents of the array are truncated and do not show all 4096 elements.

The debugger sees the arrays no problem, it just fails to give me all of the array data (as far as I can tell)

I've attached a screenshot of the Watch List + Evluate/Modify

You can see in Evaluate/Modify it gets truncated at a byte with the value of 13 (and then followed by "...")

Whereas the last element should be 97, as seen by readBuffer[0][4095] in the watch list.

And I copied the contents of Evaluate/Modify to another program to count its lines which ends at 2500. So the results are truncated and I do not know why.

I guess to add further info, Windows 10 64 bit, Lazarus 1.8.0 with FPC 3.0.4
« Last Edit: March 19, 2018, 09:43:00 am by daz »

Thaddy

  • Hero Member
  • *****
  • Posts: 6099
Re: Inspecting larger array sizes
« Reply #3 on: March 19, 2018, 09:44:28 am »
It is probably a limitation of the watch list. You can use my second screenshot example to assign the high part of every fixed array[x,y] in that case.
I will add an example to work around this.
[edit]
Example range should be  4103 i+j-9+1 = 4095, so it works:
Code: Pascal  [Select]
  1. program debugarray;
  2. {$D+}
  3. {$ofopt D+}
  4. type
  5.   TArray10 = array[0..9] of integer;
  6.   PArray10 = ^TArray10;
  7. {$endif}
  8. var
  9.   A:array of array[0..4095] of integer;
  10.   {$ifopt D+}
  11.   B:array[0..9] of integer;// debug proxy
  12.   {$endif}
  13. var i,j:integer;
  14. begin
  15.   Setlength(A,10);
  16.   for i := 0 to 9 do
  17.    for j := 0 to 4095 do
  18.     A[i,j] := i+j;
  19. {$ifopt D+}
  20.   B := PArray10(@A[9,4085])^;
  21. {$endif}
  22.   writeln(B[5]);
  23. end.
« Last Edit: March 19, 2018, 09:58:33 am by Thaddy »
I might not give the answer that you want me to.. Peter Green 1969

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4587
    • wiki
Re: Inspecting larger array sizes
« Reply #4 on: March 19, 2018, 09:53:05 am »
Tools > Options > Debugger

in the property grid, adjust: max length for string

Thaddy

  • Hero Member
  • *****
  • Posts: 6099
Re: Inspecting larger array sizes
« Reply #5 on: March 19, 2018, 10:00:20 am »
Aha, didn't know that. Does not work too well. I think my example is still easier to use. [edit] That setting looked like it works, but...
« Last Edit: March 19, 2018, 10:06:42 am by Thaddy »
I might not give the answer that you want me to.. Peter Green 1969

daz

  • Full Member
  • ***
  • Posts: 106
    • http://matt-shaffer.com
Re: Inspecting larger array sizes
« Reply #6 on: March 19, 2018, 10:10:56 am »
Tools > Options > Debugger

in the property grid, adjust: max length for string
Thank you! Maybe I glanced too quickly through the options when I first checked and stopped reading at "string" before I saw the value was a suspiciously exact 2500 like what I was seeing.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4587
    • wiki
Re: [resolved] Inspecting larger array sizes
« Reply #7 on: March 19, 2018, 10:16:46 am »
It is confusing.

This is a setting coming from gdb.

But then, 2500 chars are not really easy to read. how to you know what is position e.g. 1798?

If you need 20 values from pos 1790 onwards, then do
  yourarray[1790]
and set (in watch properties) "repeat count" to 20

Note:
"repeat count"  is slow if you do a 100 or more

Thaddy

  • Hero Member
  • *****
  • Posts: 6099
Re: [resolved] Inspecting larger array sizes
« Reply #8 on: March 19, 2018, 10:49:18 am »
Note:
"repeat count"  is slow if you do a 100 or more
Very slow for 4096 items (or even 4096^2). That's why I think my third solution works better (even if a copy operation is involved) than setting the string length.
And the extra code disappears in release mode. And it is much faster.

Anyway your way works without modification and is probably better.
« Last Edit: March 19, 2018, 11:13:28 am by Thaddy »
I might not give the answer that you want me to.. Peter Green 1969

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4587
    • wiki
Re: [resolved] Inspecting larger array sizes
« Reply #9 on: March 19, 2018, 12:05:15 pm »
Note:
"repeat count"  is slow if you do a 100 or more
Very slow for 4096 items (or even 4096^2). That's why I think my third solution works better (even if a copy operation is involved) than setting the string length.

"repeat count" and "max string len" are different things.

"repeat count" is slow
 "max string len" should perform ok

 "max string len" has no effect on dynamic array, only static (maybe even only array [...] of byte (or char) because gdb may think it is a string


 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus