Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault #6

Open
dwjbosman opened this issue Oct 9, 2024 · 3 comments
Open

Segmentation fault #6

dwjbosman opened this issue Oct 9, 2024 · 3 comments

Comments

@dwjbosman
Copy link

I am testing strtt on a STM32U5, it finds the RTT info but then crashes

./strtt -v 4 -ramstart 0x2023af49

I added some debugging code, but I don't know how to fix this:

    strtt.cpp:272
    
    // 2. Enumerate buffers start and size
    for (size_t i = 0; i < buffersCnt; i++)
    {
        // check only valid channels, eg. with size > 0 AND and something to read
        SEGGER_RTT_BUFFER bufferDesc = this->_rtt_info.pRttDescription->buffDesc[i];
        if ((bufferDesc.SizeOfBuffer) && (bufferDesc.RdOff != bufferDesc.WrOff))
        {
            start = bufferDesc.pBuffer - ramStart;
            size = bufferDesc.SizeOfBuffer;
            LOG_DEBUG("readrtt: pushblock pb=%u, rs=%u start = %u, size = %u",bufferDesc.pBuffer, ramStart,start, size);
            blocks.push_back(std::make_pair(start, size));
        }
    }

Debug: 96 62 strtt.cpp:281 readRtt(): readrtt: pushblock pb=539208521, rs=539209545 start = 4294966272, size = 1024

Somehow bufferDesc.pBuffer < ramStart, which causes start to overflow, which in turn causes _memory[start] to fail.

    LOG_DEBUG("readrtt: read2 %u bytes start=%u memsz=%lu", size,start, this->_memory.size());
    // ret = stlink_usb_layout_api.read_mem(this->_handle, start + RAM_START, -1, size, &this->_memory[start]);
    ret = stlink_usb_layout_api.read_mem(this->_handle, start + ramStart, -1, ((size / 4) * 4) + 4, &this->_memory[start]);
@dwjbosman
Copy link
Author

Ok, it seems that if the actual data transfer buffer is before the ramstart parameter, the app crashes.

So I started the app with a lower ramstart and larger ramsize. Now it runs.

It could be a solution to resize the memory cache if it finds bufferDesc.pBuffer < ramStart and then to adjust ramStart

@phryniszak
Copy link
Owner

Good finding. Can you send some code that let me replicate this and I try to fix it?

@dwjbosman
Copy link
Author

Sorry, I can't share the code.

If you check SEGGER_RTT.c the _acDownBuffer is allocated, and also _SEGGER_RTT

You could move the allocations to ensure that _acUpBuffer is allocated to an address lower than _SEGGER_RTT
2.
And then in the .map file find the exact address of _SEGGER_RTT

Start the rtt viewer with -ramstart setting of the exact _SEGGER_RTT address

This will trigger the fault

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

No branches or pull requests

2 participants