[PATCH v4 2/5] elf: Add SFrame stack tracing

Jens Remus jremus@linux.ibm.com
Tue Apr 22 08:41:01 GMT 2025


On 18.04.2025 17:09, Florian Weimer wrote:
> * claudiu zissulescu-ianculescu:
> 
>> +/* Initialize the SFrame backtrace routine, and try to backtrace the
>> +   current stack using SFrame info.  The return value of SFrame stack
>> +   tracer must be larger than one to consider the SFrame backtrace
>> +   valid. Otherwise, there may be the case that glibc is compiled
>> +   using SFrame but the application not.   */
>> +
>> +#define DO_SFRAME_BACKTRACE(ARRAY, SIZE)			\
>> +  do								\
>> +    {								\
>> +      int cnt;							\
>> +      frame frame;						\
>> +      frame.pc = getPC();					\
>> +      frame.sp = getSP();					\
>> +      frame.fp = (_Unwind_Ptr) __builtin_frame_address (0);	\
>> +      cnt = stacktrace_sframe (ARRAY, SIZE, &frame);		\
>> +      if (cnt > 1)						\
>> +	return cnt;						\
>> +    }								\
>> +  while(0)
> 
> Shouldn't this switch to DWARF backtracing to avoid a truncated
> backtrace?  Otherwise std::stacktrace::current() will not work anymore
> once glibc and libstdc++ are upgraded, I think.

If the returned count is equal or less than 1 (accounting for backtrace
itself), then the logic falls back to DWARF backtracing.  If the count
is greater than 1, the assumption is that SFrame backtracing is complete.
I am not sure whether it would be possible to distinguish whether SFrame
backtracing reached a terminal frame (e.g. _start) or failed to fallback
to DWARF backtracing in the latter case.

Regards,
Jens
-- 
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
jremus@de.ibm.com

IBM

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/



More information about the Libc-alpha mailing list