Sign in Join
Wiki copytemporary

FpDebug-Watches-Intrinsic-Functions

About

LazDebuggerFp has some build in helper functions and operators. They can be included in any watch using the pascal function calling syntax. The result is calculated internally be the debugger.

To avoid clashed with identifier names in the debugged target app, such intrinsic functions require a ":" prefix by default. E.g. ":length(s)".

Intrinsic Operators

Array slice MyArray[n..m] with mapping

The array slice operator is available in freepascal, when calling a function that accepts an open array.

FpDebug extends this operator. The returned array slice can map any operation on its members. That is, if you do MyArray[1..5]+4 then the +4 will not act on the array slice, but instead on each entry in the slice.

This is true for any operation (including further index operations).

String slice MyString[n..m]

Select a substring.

Unlike the array-slice, this returns a single string and not an array of chars. Therefore any operation on the result will affect the single string, and not each char.

Similar to the intrinsic SubStr. For strings this is always limited to the bounds. SubStr can use "ForcePtr" to ignore bounds.

Intrinsic Functions

Settings

The prefix can be chosen or switched off. In the property grid of the debugger backend setup the option "IntrinsicPrefix" can be found.

CC(instance) {ChildClass}

Type-casts an object (class instance) to the instantiated class type.

E.g. "Sender: TObject" is by default evaluated as TObject. ":CC(Sender)" will find the actual class of the instance and the result will be e.g. a TButton or TForm. ":CC(Sender)" is the same as either writing "TForm(Sender)" or "TButton(Sender)", but automatically adapts to the correct type.

Simply watching ":CC(Sender)" returns the same result as checking the "Use instance class" checkbox in the watches properties.

The difference between ":CC()" and "Use instance class" is

The "Use instance class" checkbox can then be used on the result of ":CC(Sender).FOwner"

":CC()" takes exactly one argument. If the argument is not an object, or can not be typecasted, then it is passed through. E.g. ":CC(1)" just return "1".

Length(String-or-array)

Returns the length of an array or string.

See FpDebug#Strings_(vs_PChar_and_Array_of_Char) for info about string types in the debugger.

RefCnt(string-or-array)

Get FPC's internal ref-count for LongString(AnsiString) or dynamic arrays.

Strings may work only with DWARF-3.

== Pos(SubString, MainString [, CaseInsensitive=False]) ==

Works like the "Pos" function.

Accepts an optional 3rd argument of boolean type. If True, both strings will be run through "LowerCase" to make it case insensitive. (May not work for utf-8)

== SubStr(Str, Start, Len [, ForcePtr=False]) ==

Similar to "copy()"

Gets a substring.

Note: the handling of String vs Pchar may depend on the Dwarf version and the debuggers ability to distinguish between PChar and String

Using Dwarf-2 a string may be seen as pchar instead

If acting on a string:

If acting on Pointers or ForcePtr

"Start" can be negative.

This function will be limited my the MaxStringLen and MaxMemReadSize LazDebuggerFp#Debugger_specific_options

Lower(Str) / Upper(Str)

Take a string as argument and lower/upper-case it.

This function will be limited my the MaxStringLen and MaxMemReadSize LazDebuggerFp#Debugger_specific_options

Trunc(float)

Truncates a float to integer.

Round(float, [digits])

rounds a float.

If digits are not specified or zero, then the result is integer. Otherwise the result is floating point.

Note that digits should be negative to keep decimals after the dot.


From the Free Pascal wiki, page "FpDebug-Watches-Intrinsic-Functions", as it stood on 2023-06-28 after a change by Martin, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.