View Issue Details

IDProjectCategoryView StatusLast Update
0020286LazarusIDEpublic2014-09-10 17:29
Reporterrfsanet Assigned To 
PrioritynormalSeveritymajorReproducibilityhave not tried
Status acknowledgedResolutionopen 
PlatformWIN32OSWindows Vista 
Summary0020286: GDB raises SIGSEGV error in String local variable changing
DescriptionWhen I try to modify a String local variable at runtime, Lazarus raises the SIGSEGV error. I think that the error occurs for function TGDBMIDebugger.GDBModify uses the folowing command:

Result := ExecuteCommand('-gdb-set var %s := %s', [AExpression, S], [cfIgnoreError, cfExternal], R) and (R.State <> dsError);

Testing in the GDB.EXE, I saw that the correct command should be call [strncpy(Text, "newValue", NewSize))] instead [set var Text := "newValue"].

The NewSize value will be the greater of initial value size and new value size.

Can anybody help me to fix the error?
Steps To ReproduceUnzip the Project.7Z (folder: C:\TEST\Project)
Run cmd.exe
cd /d C:\TEST\Project
 file project1.exe
 break 20
 set var TextVar := "NewValue"

 Program received signal SIGSEGV, Segmentation fault.
 0x0044a0f6 in LCLPROC_$$_CONVERTUTF8TOUTF16$crc2EBDF3EE ()

Alternative commands:

Unzip the Project.7Z (folder: C:\TEST\Project)
Run cmd.exe
cd /d C:\TEST\Project
 file project1.exe
 break 20
 call strncpy(TextVar, "NewValue", strlen("InitialValue"))
TagsNo tags attached.
Fixed in Revision
Attached Files


related to 0017619 closedMartin Friebe Lazarus Debugger handles strings as 0-based, while they are 1-based. Leading to wrong char being displayed 
has duplicate 0020287 closedJonas Maebe FPC GDB raises SIGSEGV error in String local variable changing 


2011-09-18 17:32


Project.7z (654,649 bytes)

Jonas Maebe

2011-09-18 17:43

manager   ~0051987

strncpy is definitely not correct either. I don't think this can be easily solved in either Lazarus or GDB at this time, because there is no publicly documented (and hence guaranteed stable) function in the FPC RTL for assigning new string values to variables.

The proper way to deal with this in Lazarus at this time would probably be to give an error message when someone attempts to change the value of a string.

Martin Friebe

2011-09-18 18:48

manager   ~0051989

At current all handling of string, pchar, array of char is limited to do limits in gdb, or the stabs/dwarf debug info.

A proper implementation is currently not possible, therefore target post 1.2 (It may be changed to earlier, if development within fpc, gdb and/or lazarus make this possible)

The implementation of a safety check to prevent the attempt of setting a value to a string or similar type will be reviewed at an earlier stage.

Thanks for reporting.


2011-09-18 22:14

reporter   ~0051999

Thanks for reply!

Despite the instability, I think valid to be enabled the option to modify String local variables even with warning of risks.

What about we proceed?

Martin Friebe

2011-09-18 23:40

manager   ~0052003

Yes, there will probably be an option, so it will be a warning, and the user can force the current behaviour.

There are currently other issues, that are being worked on. This issue will be proceeded, when time becomes available (sorry it may be a while before anything will be done).

Please also note, that even a warning, is by far more complex than it may sound. To detect if the variable which is about to be assigned to, is a string or similar type, may depend on the version of gdb, version of fpc, and type of debug info. This means it will be necessary to run a huge amount of tests.

Issue History

Date Modified Username Field Change
2011-09-18 17:32 rfsanet New Issue
2011-09-18 17:32 rfsanet File Added: Project.7z
2011-09-18 17:43 Jonas Maebe Note Added: 0051987
2011-09-18 17:43 Jonas Maebe Project FPC => Lazarus
2011-09-18 18:38 Jonas Maebe Relationship added has duplicate 0020287
2011-09-18 18:48 Martin Friebe LazTarget => post 1.2
2011-09-18 18:48 Martin Friebe Note Added: 0051989
2011-09-18 18:48 Martin Friebe Status new => acknowledged
2011-09-18 18:49 Martin Friebe Relationship added related to 0017619
2011-09-18 22:14 rfsanet Note Added: 0051999
2011-09-18 23:40 Martin Friebe Note Added: 0052003
2013-09-03 12:07 Martin Friebe LazTarget post 1.2 => 1.4
2014-09-10 17:29 Juha Manninen LazTarget 1.4 => -