Recent

Author Topic: Error: Project raised exception class 'External:SIGSEGV'.  (Read 225792 times)

OttoMan28

  • New member
  • *
  • Posts: 5
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #75 on: May 14, 2016, 08:50:46 pm »
I'm sad to say, its also there in 1.6.0 - I just ran into also.
Will give the error on a simple form with just a button or so.
However the .exe will work fine.

Any suggestions ?

I'm using a Win7, 64 bit
Old Compass/Poly Pascal guy, climbing the learning curve of Lazarus :-/
So n00bs questions might follow...

OttoMan28

  • New member
  • *
  • Posts: 5
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #76 on: May 14, 2016, 10:40:35 pm »
Well, a reinstall of Lazarus removed the problem.  :o
That is comforting ... not.
Old Compass/Poly Pascal guy, climbing the learning curve of Lazarus :-/
So n00bs questions might follow...

BMUN1

  • Newbie
  • Posts: 3
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #77 on: June 12, 2016, 03:19:29 am »
Hi guys,

I have Laz 1.6 on W10x64 using MSSQL 2008 r2 DB and I still consistently get SIGSEGV error at runtime (from IDE or external exe) with any data control that is clicked on or attempting to nav a dataset. Appears to be on dataChange event (tried both TDBGrid and TDBNavigator separately and together)

Holding out for a hero...

ezlage

  • Guest
« Last Edit: June 12, 2016, 05:15:11 am by ezlage »

BMUN1

  • Newbie
  • Posts: 3
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #79 on: June 13, 2016, 02:22:57 am »
Thanks friend. I don't know if resetting debugger to alt GDB fixed it or the 5 reinstalls did but in the end my only problem was a bunch of package compiles erroring on files not found. I just copied the files it couldn't find to the units dir and now everything works. Thanks again!

pixelink

  • Hero Member
  • *****
  • Posts: 1243
    • Pixelink Software
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #80 on: August 21, 2016, 12:40:09 pm »
I got the same error 'External SIGSEGV' today....

And what I did was so simple to do to fix it. (the docs mention string problems in DLL's)

I replaced "string' with PChar (this is for Windows machines)

THE DLL:
Code: Pascal  [Select][+][-]
  1. Function getMsg():String; stdcall;
  2.  
  3. to
  4.  
  5. Function getMsg():PChar; stdcall;
  6.  

THE APP:
Code: Pascal  [Select][+][-]
  1. type
  2.   TMyDLL = function(): String; stdcall;
  3.  
  4. to
  5.  
  6. type
  7.   TMyDLL = function(): PChar; stdcall;
  8.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Media
LAZ 2.08 •  VSSTUDIO(.Net) 2019 • Win10 • 16G RAM • Nivida GForce RTX 2060

Akira1364

  • Hero Member
  • *****
  • Posts: 543
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #81 on: August 21, 2016, 04:53:36 pm »
Regarding GDB in general, I've found that the builds of 7.9 available here work very well with Lazarus:
http://www.equation.com/servlet/equation.cmd?fa=gdb

steve.huang

  • Newbie
  • Posts: 3
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #82 on: October 24, 2016, 10:09:54 am »
I got the same error 'External SIGSEGV' today....

And what I did was so simple to do to fix it. (the docs mention string problems in DLL's)

I replaced "string' with PChar (this is for Windows machines)

THE DLL:
Code: Pascal  [Select][+][-]
  1. Function getMsg():String; stdcall;
  2.  
  3. to
  4.  
  5. Function getMsg():PChar; stdcall;
  6.  

THE APP:
Code: Pascal  [Select][+][-]
  1. type
  2.   TMyDLL = function(): String; stdcall;
  3.  
  4. to
  5.  
  6. type
  7.   TMyDLL = function(): PChar; stdcall;
  8.  
I did it follow your suggestion,but got a wrong return result when I try to convert the PChar to string with StrPas()

Thaddy

  • Hero Member
  • *****
  • Posts: 10796
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #83 on: October 24, 2016, 10:16:40 am »
StrPas is old school. Assign the PChar to a string like so. string := pchar;
The compiler will do that for you if the PChar is correct and valid in the first place.
Code: Pascal  [Select][+][-]
  1. function gimmeastring(const a:pchar):string;inline;  // this is supposed to do what strpas does ;) Make a copy, refcounted.
  2. begin
  3.   result := a;
  4. end;

Or better:
Code: Pascal  [Select][+][-]
  1. var
  2.   a:PChar;
  3.   b:string;
  4. begin
  5.   b := a;
  6. end.
   

If that does not work you wrote wrong code. Simple as that.
« Last Edit: October 24, 2016, 10:27:51 am by Thaddy »

steve.huang

  • Newbie
  • Posts: 3
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #84 on: October 25, 2016, 06:29:08 am »
Code: Pascal  [Select][+][-]
  1. library mydll;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Classes, SysUtils, Windows
  7.   { you can add units after this };
  8. function myMessage(): string; stdcall;
  9.   begin
  10.      MessageBox(0,PChar('Hello world'),PChar(''),MB_OK);
  11.    end;
  12.  
  13. Function WinUserName(): PChar; stdcall;
  14. var
  15.    FStr: PChar;
  16.    FSize: Cardinal;
  17. begin
  18.    FSize := 255;
  19.    GetMem(FStr, FSize);
  20.    Windows.GetUserName(FStr, FSize);
  21.    Result :=FStr;
  22.    FreeMem(FStr);
  23. end;
  24.  
  25.  
  26. exports
  27.    myMessage,WinUserName;
  28.  
  29.  
  30. end.                              
  31.  

Code: Pascal  [Select][+][-]
  1. procedure TForm1.BitBtn1Click(Sender: TObject);
  2. var
  3.   MyHandle: TLibHandle;
  4.   MyDLL: TMyDLL;
  5.   userId: string;
  6.  MyHandle := LoadLibrary('mydll.dll');
  7.   if MyHandle<>0 then
  8.     begin
  9.       pointer(MyDLL):=getProcedureAddress(Myhandle,'WinUserName');
  10.       if Assigned(MyDLL) then
  11.         begin
  12.           userid:=MyDLL();
  13.           edit2.text:=userid;
  14.         end;
  15.     end    
  16.  
The same wrong return result as StrPas

Cyrax

  • Hero Member
  • *****
  • Posts: 835
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #85 on: October 25, 2016, 10:51:35 am »
Code: Pascal  [Select][+][-]
  1. library mydll;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Classes, SysUtils, Windows
  7.   { you can add units after this };
  8. function myMessage(): string; stdcall;
  9.   begin
  10.      MessageBox(0,PChar('Hello world'),PChar(''),MB_OK);
  11.    end;
  12.  
  13. Function WinUserName(): PChar; stdcall;
  14. var
  15.    FStr: PChar;
  16.    FSize: Cardinal;
  17. begin
  18.    FSize := 255;
  19.    GetMem(FStr, FSize);
  20.    Windows.GetUserName(FStr, FSize);
  21.    Result :=FStr;
  22.    FreeMem(FStr)
  23. end;
  24. ...
  25.  
...

Remove FreeMem(FStr) and do your cleaning up (freeing memory etc.) in your main code.

steve.huang

  • Newbie
  • Posts: 3
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #86 on: October 25, 2016, 11:10:53 am »
Code: Pascal  [Select][+][-]
  1. library mydll;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Classes, SysUtils, Windows
  7.   { you can add units after this };
  8. function myMessage(): string; stdcall;
  9.   begin
  10.      MessageBox(0,PChar('Hello world'),PChar(''),MB_OK);
  11.    end;
  12.  
  13. Function WinUserName(): PChar; stdcall;
  14. var
  15.    FStr: PChar;
  16.    FSize: Cardinal;
  17. begin
  18.    FSize := 255;
  19.    GetMem(FStr, FSize);
  20.    Windows.GetUserName(FStr, FSize);
  21.    Result :=FStr;
  22.    FreeMem(FStr)
  23. end;
  24. ...
  25.  
...

Remove FreeMem(FStr) and do your cleaning up (freeing memory etc.) in your main code.
Write sample code here please!

karmacomposer

  • New Member
  • *
  • Posts: 25
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #87 on: December 08, 2020, 03:57:02 pm »
I am getting this same problem.

This function (not written by me) is causing it:

Code: [Select]
function BinStr2Hex(S: AnsiString): AnsiString;
var
  i: integer;
begin
  Result := '';
  for i := 1 to Length(S)
    do Result := Result + LowerCase(HexStr(Byte(S[i]), 2));
end;

I tried PChar, I tried other things.  It always causes the error.

I am trying to encrypt a piece of data with DCPcrypt2 and this function turns the binary result into a hex string.

How can this be used and not throw that error?

Thanks.

Mike

rvk

  • Hero Member
  • *****
  • Posts: 4479
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #88 on: December 08, 2020, 04:46:21 pm »
Are you sure that the "S" string isn't zero-length?
That wouldn't matter for that function.
"for i := 1 to 0 do" won't execute anything.

I am getting this same problem.
This function (not written by me) is causing it:
Code: [Select]
function BinStr2Hex(S: AnsiString): AnsiString;
Could you show how this function is called.
The function itself should work fine with an ansistring as parameter.
« Last Edit: December 08, 2020, 04:49:46 pm by rvk »

Peter H

  • Full Member
  • ***
  • Posts: 197
Re: Error: Project raised exception class 'External:SIGSEGV'.
« Reply #89 on: December 08, 2020, 05:15:47 pm »
The error happens at this function, this doesnt mean, this function causes it.
Probably this means the problem is detected when the memory where the string is stored is accessed.

SigSEV means: "invalid memory access" and there should be a line number displayed, where the progamm fails.

If there is something wrong with the memory of the string argument, the error should occur when the content of the string is accessed.
So set a breakpoint there and examine the content of the string, or/and insert a Writeln or debugln to see the contents.

Probably the string is trashed by an array overflow or is uninitialized.
If the program is large or recursive, or the string is very large, stack overflow could be a reason.
(I believe there is a write protected guard page at the end of the stack segment, that causes SigSEV at stack overflow, but I do not know it)
Also I recommend to pass the string not by value but by reference as "constref" or "var" parameter to reduce unnecessary stack consumption and for performance.

« Last Edit: December 08, 2020, 05:40:13 pm by Peter H »

 

TinyPortal © 2005-2018