Hi All.
In my co de below everything works fine till function libusb_get_string_descriptor_ascii. Here project stops with E: Project raised exception class EXTERNAL:SIGSEGV At address B7FB0638
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, libusb;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
max_list: size_t;
list: PPPlibusb_device;
myP_Device: Plibusb_device;
myP_Descriptor: Plibusb_device_descriptor;
myDescriptor: libusb_device_descriptor;
myP_DevHandle : Plibusb_device_handle;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
strDesc : packed array [0..20] of char;
retVal : byte;
I: Integer;
begin
ListBox1.Items.Clear;
libusb_init(nil);
max_list := libusb_get_device_list(nil, @list);
for I := 0 to max_list - 1 do
begin
myP_Device := @list[I]^;
try
retVal := libusb_open(myP_Device, @myP_DevHandle);
except
if (retVal <> LIBUSB_SUCCESS) then
ShowMessage(' chyba so spravou: retVal != LIBUSB_SUCCES');
end;
libusb_get_device_descriptor(myP_Device, @myP_Descriptor);
myDescriptor := Plibusb_device_descriptor(@myP_Descriptor)^;
ListBox1.Items.Add(IntToStr(I+1) +'. -VID: ' + IntToHex(myDescriptor.idVendor,4) + ' -PID: ' + IntToHex(myDescriptor.idProduct,4));
libusb_get_string_descriptor_ascii(myP_DevHandle ,myDescriptor.iProduct, strDesc, length(strDesc)); // <- problem
ListBox1.Items.Add(strDesc);
try
libusb_close(myP_DevHandle);
except
on E : ExceptioN do ShowMessage(E.Classname+ ' chyba so spravou: '+E.Message);
end;
myP_DevHandle := nil;
end;
libusb_exit(nil);
end;
end.
Here is function declaration from libusb.pp
function libusb_get_string_descriptor_ascii(dev:plibusb_device_handle ;index:uint8_t; data:Pchar; length:integer):Integer;cdecl;external;
Here is an assembler window
B7FB061C 8d742600 lea 0x0(%esi,%eiz,1),%esi
libusb_submit_transfer
B7FB0620 55 push %ebp
B7FB0621 57 push %edi
B7FB0622 56 push %esi
B7FB0623 53 push %ebx
B7FB0624 83ec4c sub $0x4c,%esp
B7FB0627 8b742460 mov 0x60(%esp),%esi
B7FB062B e8c0b7ffff call 0xb7fabdf0 <__x86.get_pc_thunk.bx>
B7FB0630 81c3d0f90000 add $0xf9d0,%ebx
B7FB0636 8b06 mov (%esi),%eax
B7FB0638 8b4024 mov 0x24(%eax),%eax <- problem
B7FB063B 8b401c mov 0x1c(%eax),%eax
B7FB063E 89442420 mov %eax,0x20(%esp)
B7FB0642 8d46e8 lea -0x18(%esi),%eax
What I am doing wrong?
Linux Mageia4 32bit, Lazarus 1.2.6