Skip to content

do not overwrite cuInfo->low, it's the base of a range - #11

Closed
oltolm wants to merge 1 commit into
ssbssa:masterfrom
oltolm:lowpc
Closed

do not overwrite cuInfo->low, it's the base of a range#11
oltolm wants to merge 1 commit into
ssbssa:masterfrom
oltolm:lowpc

Conversation

@oltolm

@oltolm oltolm commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

The code overwrites cuInfo->low with a low from a range

            if( !hasLow || low<cuInfo->low )
            {
              cuInfo->low = low;
              hasLow = 1;
            }

and then uses cuInfo->low as the base of a range

            inline_info ii = { ptr,cuInfo->low,
              files,fileCount,callbackFunc,callbackFuncW,callbackContext,
              ptrOrig,(int)srcfileno+cuInfo->fileno_offs,lineno,columnno,
              cuInfo->fileno_offs };
            walkChildren( dbg,die,(ChildWalker*)findInlined,&ii );

That is not correct. The base of a range, according to spec, must be lowpc from a CU. This code is an optimization that has no influence on the runtime, I tested it. The patch simply removes the code.

I would also remove code like

      int hasLow = res==DW_DLV_OK && cuInfo->low;
      if( !hasLow ) cuInfo->low = 0;
      cuInfo->high = 0;

dwarf_lowhighpc does not change its out parameters in case of an error, so it's unnecessary defensive programming.

@ssbssa

ssbssa commented Aug 30, 2026

Copy link
Copy Markdown
Owner

The would revert parts of 742f4ec, which I vaguely remember was needed for some debug infos I encountered.
And cuInfo->low/high have to be the minimum/maximum respectively, because they are later used to check if an address is contained in the CU.

@ssbssa ssbssa closed this Aug 30, 2026
@oltolm

oltolm commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

But the code right now overrides the lowpc from the CU. If the CU lowpc is 0, it will be overwritten with a non-zero low from a range. This is a common case. I could probably provide a test that reproduces the range base bug.

Why do you need the minimum and maximum when you can simply iterate over a range. Is it for performance reasons? I can provide them separately instead of overwriting the range base, although as I said I benchmarked it.

@ssbssa

ssbssa commented Aug 30, 2026

Copy link
Copy Markdown
Owner

But the code right now overrides the lowpc from the CU. If the CU lowpc is 0, it will be overwritten with a non-zero low from a range. This is a common case. I could probably provide a test that reproduces the range base bug.

I wasn't aware that lowpc could be 0, so yes, I would like to see how to reproduce that.

@oltolm

oltolm commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

I pushed a new commit with the test to this branch oltolm@54c1842.

If you build with CMake, just run ctest, otherwise build test-cu-ranges.exe and a2l.exe and run test-cu-ranges .\a2l.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants