[fpc-devel] Question: ref counts / strings, smart pointers...
Martin Frb
lazarus at mfriebe.de
Wed May 27 12:11:07 CEST 2026
I know how refcount internally work on strings and dyn array.
I am thinking about formulating a request to the DWARF specs. So I want
to check the details, and also get information how they
- will work for smart pointers,
- where else they may occur?
Background, refcounts may be of interest for the debugger in at least
the following cases.
- A user modifies a variable (or an indexed value) via the debugger.
~ The debugger may additionally need info, if it should "copy on
write" / though that can be derived....
~ The debugger could inform the user about "side effects on other
references to the value"
- The user may want to explicitly see the refcount.
~ A user may have "pchar" access to a string, and the user wants to
ensure the string was correctly "uniquestring" treated.
- A user wants to call a function that has a string/array as
argument/result.
~ The debugger must deal with that, without introducing mem leaks.
If I am correct, then the following dwarf tags may need information
DW_TAG_Array (string and array)
DW_TAG_string_type
DW_TAG_structure // or class / interface => for smart pointers
// other types? base type, e.g. a refcounted char or integer???
The last assumes that the info can be encoded to the "smart pointed to"
structure?
- Are there non-structure values that could be affected?
- Should maybe the DW_TAG_Pointer hold the refcount info instead?
I would expect the ref-count to be in the target value? Unless you can
have a non-ref-counted structure, but have a ref-counted pointer to it????
------------------
The "copy on write" can be known by checking if it is a string. That is,
as long as smart pointers will not look like a string.
The debugger likely will need some knowledge on the producer (and then
such type based decisions can be allowed)>
This is because the debugger must also know how to call
fpc_ansistring_decref etc...
And trying to encode what functions to call (including where to pass
which data as parameter =>probably way to complex)
So my current idea is to request a simple
DW_AT_refcount // location, reference, constant // maybe flag
maybe
DW_AT_refcount_size / bit_size
(And maybe similar for the encoding field... any idea on what other
fields may be of interest, or any that are going to be added soon-ish?)
------------------
I am not sure yet which methods the debugger may have to call on smart
pointers, or what else it would need to know.
Any feedback on that part would be welcome
More information about the fpc-devel
mailing list