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

Fix bug with parsing UART output #318

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

XingMicrochip
Copy link
Contributor

This PR fixes issue #317.

Problematic code snippet in GDBTargetDebugSession.ts:

            const eolChar: string =
                uart.eolCharacter === 'CRLF' ? '\r\n' : '\n';

            let tcpUartData = '';
            this.socket.on('data', (data: string) => {
                for (const char of data) {
                    if (char === eolChar) {
                        this.sendEvent(
                            new OutputEvent(tcpUartData + os.EOL, 'Socket')
                        );
                        tcpUartData = '';
                    } else {
                        tcpUartData += char;
                    }
                }
            });

If data is CoreTimer timer interrupt.\r\n - for example - without setting eolCharacter in launch configuration, the adapter uses default \n to parse data. It accumulates CoreTimer timer interrupt.\r in variable tcpUartData and then appends os.EOL at the end. On Windows, the final tcpUartData becomes CoreTimer timer interrupt.\r\r\n. The extra new line comes from here. To fix this, the adapter appends \n instead of \r\n because \r is already in tcpUartData.

I tried setting eolCharacter to CRLF in launch configuration. This didn't work. char is one character in length, but eolChar is two in length, so char === eolChar is never true. The adapter also can't parse two characters at a time because one burst of data might be CoreTimer timer interrupt.\r and the next one \n. If this happens, \r\n will never be detected together.

I have tested this change fixes the problem I described in issue #317.

Copy link
Contributor

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks fine to me, but it would be nice to have a test that demonstrates it and prevents it regressing.

src/GDBTargetDebugSession.ts Show resolved Hide resolved
src/GDBTargetDebugSession.ts Show resolved Hide resolved
@XingMicrochip
Copy link
Contributor Author

I will add a test.

@jonahgraham
Copy link
Contributor

I will add a test.

Great! Seeing as there are already some failing tests with the change you provided it may be worth looking into whether there is already a test that just needs a modification.

@XingMicrochip
Copy link
Contributor Author

Can you re-run the tests? @jonahgraham I don't know what the one that's failing is about.

@XingMicrochip
Copy link
Contributor Author

XingMicrochip commented Nov 16, 2023

All the tests are passing now. Can you release a new version on Open VSX for this change? Thanks.

@jonahgraham
Copy link
Contributor

All the tests are passing now. Can you release a new version on Open VSX for this change? Thanks.

I'll try to look at it soon, but it may have to wait until Monday.

@XingMicrochip
Copy link
Contributor Author

That works. Thank you.

@jonahgraham jonahgraham merged commit 59af421 into eclipse-cdt-cloud:main Nov 21, 2023
3 checks passed
jonahgraham added a commit to jonahgraham/cdt-gdb-vscode that referenced this pull request Nov 21, 2023
Adds support for these features/bug fixes in the adapter:

- A fix the newline handling for the UART
  - eclipse-cdt-cloud/cdt-gdb-adapter#318
- New feature of supporting stepping granularity
  - eclipse-cdt-cloud/cdt-gdb-adapter#309
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