View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0020286LazarusIDEpublic2011-09-18 17:322013-09-03 12:07
Reporterrfsanet 
Assigned To 
PrioritynormalSeveritymajorReproducibilityhave not tried
StatusacknowledgedResolutionopen 
PlatformWIN32OSWindows VistaOS VersionHome Basic
Product VersionProduct Build 
Target VersionFixed in Version 
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
gdb.exe
 file project1.exe
 break 20
 run
 set var TextVar := "NewValue"
 cont

Error:
 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
gdb.exe
 file project1.exe
 break 20
 run
 call strncpy(TextVar, "NewValue", strlen("InitialValue"))
 cont
TagsNo tags attached.
Fixed in Revision
LazTarget1.4
Widgetset
Attached Files7z file icon Project.7z [^] (654,649 bytes) 2011-09-18 17:32

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

-  Notes
(0051987)
Jonas Maebe (manager)
2011-09-18 17:43

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.
(0051989)
Martin Friebe (manager)
2011-09-18 18:48

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.
(0051999)
rfsanet (reporter)
2011-09-18 22:14

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?
(0052003)
Martin Friebe (manager)
2011-09-18 23:40

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



MantisBT 1.2.12[^]
Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker