* * *

Author Topic: Wrong String index  (Read 1891 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4810
    • wiki
Re: Wrong String index
« Reply #15 on: August 29, 2018, 07:14:05 pm »
It should give both on all OS. I am not sure, if it detects this with Stabs debug info too....

One other reason could be a really old Lazarus.

Yet another reason could be something the way GDB works. To check this, it would be required to see how the variables are declared.
And also to have a logfile http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session

PascalDragon

  • Full Member
  • ***
  • Posts: 200
  • Compiler Developer
Re: Wrong String index
« Reply #16 on: August 29, 2018, 10:14:35 pm »
To make matters worse.. Delphi has an option to index strings from zero....(10.2)
FPC supports {$ZeroBasedStrings On} since 3.0.0 as well.  :-[

ASerge

  • Hero Member
  • *****
  • Posts: 942
Re: Wrong String index
« Reply #17 on: August 30, 2018, 08:19:41 am »
FPC supports {$ZeroBasedStrings On} since 3.0.0 as well.  :-[
Since version 2.7.1, if I remember correctly. Unfortunately, this has not been documented so far.

440bx

  • Sr. Member
  • ****
  • Posts: 292
Re: Wrong String index
« Reply #18 on: August 30, 2018, 09:35:09 am »
FPC supports {$ZeroBasedStrings On} since 3.0.0 as well.  :-[
Just curious, are zero based strings automatically null terminated as are pchar "strings" ?

tandatcr2000pro

  • Newbie
  • Posts: 4
Re: Wrong String index
« Reply #19 on: August 30, 2018, 07:17:37 pm »
Sorry for my late rep.
I've tested again with this code (img). The watch list is still wrong but the message dialog showed 'b'.
So I think it's the error of debugger (may be a debugger's bug)  :P
PS: I don't think the problem relates to PChar. In my code, str is UnicodeString, and in my test, str is string.
My watch list do not show both values like Handoko's because I set it so.
« Last Edit: August 31, 2018, 03:21:54 am by tandatcr2000pro »

Handoko

  • Hero Member
  • *****
  • Posts: 2609
  • My goal: build my own game engine using Lazarus
Re: Wrong String index
« Reply #20 on: August 30, 2018, 07:27:55 pm »
What is version of your FPC and Lazarus?

Thaddy

  • Hero Member
  • *****
  • Posts: 6904
Re: Wrong String index
« Reply #21 on: August 30, 2018, 09:17:59 pm »
FPC supports {$ZeroBasedStrings On} since 3.0.0 as well.  :-[
Since version 2.7.1, if I remember correctly. Unfortunately, this has not been documented so far.
Fortunately... 8-)
Ada's daddy wrote this:"Fools are my theme, let satire be my song."

howardpc

  • Hero Member
  • *****
  • Posts: 2780
Re: Wrong String index
« Reply #22 on: August 30, 2018, 09:48:53 pm »
Recent (Lazarus versions)/(gdb versions) offer the best of both worlds: gdb's preferred PChar interpretation and the more familiar Pascal string interpretation.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4810
    • wiki
Re: Wrong String index
« Reply #23 on: August 31, 2018, 01:08:46 am »
So I think it's the error of debugger (may be a debugger's bug)  :P

Yes, as I pointed out in my previous post:
http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Strings
The Debug info does not contain any info what the low index is.
It is a debugger limitation. If you will a bug, that is known and that cannot be fixed (at current).

This is, why (unless you play with the settings) you get shown 2 values.

-------------------
You actually can get the correct result in the debugger, but you need:
- to use "dwarf3 beta (-gw3)"
- gdb 8.1 (maybe 8.0, not tested with that)
- Probably Lazarus svn trunk (not tested with 1.8.4)
However, using dwarf3 increases the risk of gdb crashing, which means the entire debug session will be stopped and lost.

-------------------
You can also use "fpdebug"  (under Tools > Debugger), requires package LazDebuggerFp
For this you need
- Definitely latest Lazarus svn
- Set debugger type to "fpdebug"
- Dwarf3
- Maybe compile with -Xe
- no gdb required

This will show S[ i ] correct, but it will show "s" as an array, instead of as a string.
« Last Edit: August 31, 2018, 03:29:53 am by Martin_fr »

tandatcr2000pro

  • Newbie
  • Posts: 4
Re: Wrong String index
« Reply #24 on: August 31, 2018, 03:26:24 am »
What is version of your FPC and Lazarus?
FPC 1.8.4 and Lazarus 3.0.4

tandatcr2000pro

  • Newbie
  • Posts: 4
Re: Wrong String index
« Reply #25 on: August 31, 2018, 03:30:06 am »
So I think it's the error of debugger (may be a debugger's bug)  :P

Yes, as I pointed out in my previous post:
http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Strings
The Debug info does not contain any info what the low index is.
It is a debugger limitation. If you will a bug, that is known and that cannot be fixed (at current).

This is, why (unless you play with the settings) you get shown 2 values.

-------------------
You actually can get the correct result in the debugger, but you need:
- to use "dwarf3 beta (-gw3)"
- gdb 8.1 (maybe 8.0, not tested with that)
- Probably Lazarus svn trunk (not tested with 1.8.4)
However, using dwarf3 increases the risk of gdb crashing, which means the entire debug session will be stopped and lost.

-------------------
You can also use "fpdebug"  (under Tools > Debugger), requires package LazDebuggerFp
For this you need
- Definitely latest Lazarus svn
- Set debugger type to "fpdebug"
- Dwarf3
- Maybe compile with -Xe
- no gdb required

This well show S[ i ] correct, but it will show "s" as an array, instead of as a string.
Thank you. It helped me understand the problem. But I don't think I will play with risk.
btw Thanks everyone for helping me.

PascalDragon

  • Full Member
  • ***
  • Posts: 200
  • Compiler Developer
Re: Wrong String index
« Reply #26 on: August 31, 2018, 02:26:33 pm »
FPC supports {$ZeroBasedStrings On} since 3.0.0 as well.  :-[
Just curious, are zero based strings automatically null terminated as are pchar "strings" ?
Pascal strings are automatically Null terminated no matter whether they are AnsiString or UnicodeString. The $ZeroBasedStrings directive doesn't change anything in that regard only that all indices are shifted by one when accessing a string.
FPC supports {$ZeroBasedStrings On} since 3.0.0 as well.  :-[
Since version 2.7.1, if I remember correctly. Unfortunately, this has not been documented so far.
Of course it's 2.7.1 that supported it first, but like all trunk version they are in flux so one can't say that 2.7.1 supported it, cause it only supported it from the commit on. A released version - in this case 3.0.0 - either supports it or it does not.

440bx

  • Sr. Member
  • ****
  • Posts: 292
Re: Wrong String index
« Reply #27 on: August 31, 2018, 03:26:18 pm »
Pascal strings are automatically Null terminated no matter whether they are AnsiString or UnicodeString. The $ZeroBasedStrings directive doesn't change anything in that regard only that all indices are shifted by one when accessing a string.
Nice to know that for sure.  Thank you.

 

Recent

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