IdeDebugger: add Valueformatter CharArrayToString / display an array of char as a string

This commit is contained in:
Martin 2024-04-18 20:05:35 +02:00
parent 5300c27ba2
commit bbdfea8977
28 changed files with 223 additions and 1 deletions

View File

@ -292,6 +292,10 @@
<Filename Value="projectdebuglink.pas"/>
<UnitName Value="ProjectDebugLink"/>
</Item>
<Item>
<Filename Value="idedebuggervalueformatterarrayofchartostring.pas"/>
<UnitName Value="IdeDebuggerValueFormatterArrayOfCharToString"/>
</Item>
</Files>
<i18n>
<EnableI18N Value="True"/>

View File

@ -21,7 +21,7 @@ uses
IdeDebuggerValueFormatterDateTime, IdeDebuggerValueFormatterColor,
IdeDebuggerValueFormatterSetup, IdeDebuggerValueFormatterCurrency, DisplayFormatConfigFrame,
DisplayFormatDefaultsConfigFrame, IdeDebuggerDisplayFormats, IdeDebugger_DisplayFormat_Options,
ProjectDebugLink, LazarusPackageIntf;
ProjectDebugLink, IdeDebuggerValueFormatterArrayOfCharToString, LazarusPackageIntf;
implementation

View File

@ -410,6 +410,7 @@ resourcestring
ValFormatterColorRgbDec = 'RGB in decimal';
ValFormatterCurrencyName = 'Currency';
ValFormatterCharArrayToStringName = 'CharArray as String';
DispFormatDlgBtnCurrent = 'Current';
DispFormatDlgBtnAll = 'All';

View File

@ -0,0 +1,119 @@
unit IdeDebuggerValueFormatterArrayOfCharToString;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
// IdeIntf
IdeDebuggerValueFormatterIntf, IdeDebuggerWatchValueIntf,
// IdeDebugger
IdeDebuggerStringConstants, IdeDebuggerUtils;
type
{ TIdeDbgValueFormatterCharArrayToString }
TIdeDbgValueFormatterCharArrayToString = class(specialize TLazDbgIdeValueFormatterGeneric<TObject>)
public
class function GetRegisteredDisplayName: String;
function FormatValue(AWatchValue: IWatchResultDataIntf;
ADisplayFormat: TWatchDisplayFormat;
AWatchResultPrinter: IWatchResultPrinter; out APrintedValue: String
): Boolean; override;
function SupportedFeatures: TLazDbgIdeValFormatterFeatures; override;
function SupportedDataKinds: TWatchResultDataKinds; override;
end;
TIdeDbgValueFormatterRegistryCharArrayToString =
specialize TLazDbgIdeValueFormatterRegistryEntryGeneric<TIdeDbgValueFormatterCharArrayToString>;
implementation
{ TIdeDbgValueFormatterCharArrayToString }
class function TIdeDbgValueFormatterCharArrayToString.GetRegisteredDisplayName: String;
begin
Result := ValFormatterCharArrayToStringName;
end;
function TIdeDbgValueFormatterCharArrayToString.FormatValue(
AWatchValue: IWatchResultDataIntf; ADisplayFormat: TWatchDisplayFormat;
AWatchResultPrinter: IWatchResultPrinter; out APrintedValue: String): Boolean;
var
Cnt, i: Integer;
AElem: IWatchResultDataIntf;
AWideValue: WideString;
p: PChar;
pw: PWideChar;
begin
Result := (AWatchValue.ValueKind in [rdkArray]);
if not Result then
exit;
Cnt := AWatchValue.Count;
if Cnt = 0 then
exit(False);
AWatchValue.SetSelectedIndex(0);
AElem := AWatchValue.SelectedEntry;
Result := AElem.ValueKind = rdkChar;
if not Result then
exit;
case AElem.ByteSize of
1: begin
SetLength(APrintedValue, Cnt);
p := @APrintedValue[1];
p^ := AElem.AsString[1];
i := 1;
while i < Cnt do begin
AWatchValue.SetSelectedIndex(i);
AElem := AWatchValue.SelectedEntry;
inc(p);
p^ := AElem.AsString[1];
inc(i);
end;
APrintedValue := QuoteText(APrintedValue);
end;
2: begin
SetLength(AWideValue, Cnt);
pw := @AWideValue[1];
pw^ := AElem.AsWideString[1];
i := 1;
while i < Cnt do begin
AWatchValue.SetSelectedIndex(i);
AElem := AWatchValue.SelectedEntry;
inc(pw);
pw^ := AElem.AsString[1];
inc(i);
end;
APrintedValue := QuoteWideText(AWideValue);
end;
else
Result := False;
end;
end;
function TIdeDbgValueFormatterCharArrayToString.SupportedFeatures: TLazDbgIdeValFormatterFeatures;
begin
Result := [vffFormatValue, vffValueData];
end;
function TIdeDbgValueFormatterCharArrayToString.SupportedDataKinds: TWatchResultDataKinds;
begin
Result := [rdkArray];
end;
initialization
ValueFormatterRegistry.Add(TIdeDbgValueFormatterRegistryCharArrayToString);
end.

View File

@ -178,6 +178,7 @@ type
VKind = rdkChar;
protected
function GetAsString: String; inline;
function GetAsWideString: WideString; inline;
end;
{ TWatchResultValuePointer }
@ -1861,6 +1862,11 @@ begin
Result := WideChar(FNumValue);
end;
function TWatchResultValueChar.GetAsWideString: WideString;
begin
Result := WideChar(FNumValue);
end;
{ TWatchResultValuePointer }
function TWatchResultValuePointer.GetAsString: String;

View File

@ -1704,6 +1704,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr ""
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1699,6 +1699,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr ""
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1721,6 +1721,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr ""
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1751,6 +1751,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr "Přepnout záložku"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1746,6 +1746,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr "Haltepunkt umschal&ten"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1756,6 +1756,10 @@ msgstr "El depurador no ha sido capaz de modificar el valor."
msgid "Toggle &Breakpoint"
msgstr "Ac&tivar/desactivar Punto de Interrupción"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1744,6 +1744,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr "&Keskeytyskohta päälle/pois"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1751,6 +1751,10 @@ msgstr "Le débogueur n'est pas parvenu à modifier la valeur."
msgid "Toggle &Breakpoint"
msgstr "&Inverser le point d'arrêt"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1785,6 +1785,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr "החלף נקודת עצירה"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1751,6 +1751,10 @@ msgstr "A hibakereső nem tudta megváltoztatni az értéket."
msgid "Toggle &Breakpoint"
msgstr "Töréspont ki-/&bekapcsolása"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1728,6 +1728,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr ""
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1756,6 +1756,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr "&Inverti breakpoint"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1754,6 +1754,10 @@ msgstr "デバッガは値を修正できませんでした。"
msgid "Toggle &Breakpoint"
msgstr "ブレークポイントの切り替え(&B)"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1754,6 +1754,10 @@ msgstr "Derintuvė negali keisti vertės."
msgid "Toggle &Breakpoint"
msgstr "Įjungti ar išjungti stabd&os tašką"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1724,6 +1724,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr ""
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1767,6 +1767,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr "&Przełącz pułapkę"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1723,6 +1723,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr ""
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1766,6 +1766,10 @@ msgstr "O depurador foi incapaz de modificar o valor."
msgid "Toggle &Breakpoint"
msgstr "&Alternar pontos de parada"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1736,6 +1736,10 @@ msgstr "Отладчику не удалось изменить значение
msgid "Toggle &Breakpoint"
msgstr "П&ереключить точку останова"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr "TColor"

View File

@ -1740,6 +1740,10 @@ msgstr ""
msgid "Toggle &Breakpoint"
msgstr "Prepnúť &bod prerušenia"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1746,6 +1746,10 @@ msgstr "Hata ayıklayıcı değeri değiştiremiyor."
msgid "Toggle &Breakpoint"
msgstr "Kesme &noktası değiştir"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1744,6 +1744,10 @@ msgstr "Зневаджувач не зміг змінити значення."
msgid "Toggle &Breakpoint"
msgstr "Перемкнути &точку зупинки"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""

View File

@ -1742,6 +1742,10 @@ msgstr "调试器不能修改该值。"
msgid "Toggle &Breakpoint"
msgstr "切换断点(&B)"
#: idedebuggerstringconstants.valformatterchararraytostringname
msgid "CharArray as String"
msgstr ""
#: idedebuggerstringconstants.valformattercolorname
msgid "TColor"
msgstr ""