Skip to content

Conversation

yaz0r
Copy link
Contributor

@yaz0r yaz0r commented Aug 7, 2025

No description provided.

Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

Walkthrough

A new "sharedmem" monitor command was introduced to the GDB server, allowing retrieval of the WRAM shared memory name. Supporting changes include exposing the shared memory name via a new getter, ensuring consistent state management of the shared memory name, and granting GdbClient access to Memory internals.

Changes

Cohort / File(s) Change Summary
GDB Server: Monitor Command Extension
src/core/gdb-server.cc
Added a "sharedmem" monitor command to the GDB server, handling argument validation and returning the WRAM shared memory name or error messages as appropriate.
Memory Class Friend Access
src/core/psxmem.h
Added friend class GdbClient; to the Memory class, allowing GdbClient access to private/protected members.
Shared Memory Name Management (Windows)
src/support/sharedmem-windows.cc
Replaced local variable with member variable m_sharedName for storing the shared memory name, ensuring it is cleared on failures and destruction.
Shared Memory Name Getter
src/support/sharedmem.h
Added a public method getSharedName() to the SharedMem class to provide access to the shared memory name.

Sequence Diagram(s)

sequenceDiagram
    participant GDB_Client
    participant GDB_Server
    participant Memory
    participant SharedMem

    GDB_Client->>GDB_Server: monitor sharedmem wram
    GDB_Server->>Memory: (access to WRAM shared memory object)
    GDB_Server->>SharedMem: getSharedName()
    SharedMem-->>GDB_Server: shared memory name
    GDB_Server-->>GDB_Client: shared memory name\nOK
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

In the warren of code, a new path appears,
A "sharedmem" command for all GDB peers.
Memory and friends, now closer than ever,
With names that persist and vanish quite clever.
🐇 Hopping through bytes, with joy we exclaim:
"Shared memory’s easy—just call it by name!"

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/core/gdb-server.cc (1)

763-772: Consider refactoring to address complexity growth.

The static analysis tool flagged increasing cyclomatic complexity in processMonitorCommand. While this specific addition is reasonable, consider extracting individual monitor command handlers into separate methods to improve maintainability as more commands are added.

For example:

void PCSX::GdbClient::processMonitorCommand(const std::string& cmd) {
    auto words = StringsHelpers::split(cmd, " ");
    
    if (words[0] == "reset") {
        handleResetCommand(words);
    } else if (words[0] == "mountcd") {
        handleMountCdCommand(cmd, words);
    } else if (words[0] == "sharedmem") {
        handleSharedMemCommand(words);
    }
    
    write("OK");
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b0cbe5 and 07e9b47.

📒 Files selected for processing (4)
  • src/core/gdb-server.cc (1 hunks)
  • src/core/psxmem.h (1 hunks)
  • src/support/sharedmem-windows.cc (3 hunks)
  • src/support/sharedmem.h (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in the psyqo codebase, the `safe` enum is defined in the `safe-memory.hh` header file and should be ...
Learnt from: nicolasnoble
PR: grumpycoders/pcsx-redux#1850
File: src/mips/psyqo/gpu.hh:354-354
Timestamp: 2025-01-21T18:09:06.681Z
Learning: In the psyqo codebase, the `Safe` enum is defined in the `safe-memory.hh` header file and should be explicitly included when using the `Safe` enum, rather than relying on transitive includes through other headers.

Applied to files:

  • src/core/psxmem.h
🪛 GitHub Check: CodeScene Cloud Delta Analysis (main)
src/core/gdb-server.cc

[warning] 763-772: ❌ Getting worse: Complex Method
PCSX::GdbClient::processMonitorCommand increases in cyclomatic complexity from 13 to 16, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: toolchain
  • GitHub Check: build-openbios
  • GitHub Check: aur-build
  • GitHub Check: asan
  • GitHub Check: coverage
  • GitHub Check: cross-arm64
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: build
🔇 Additional comments (5)
src/core/psxmem.h (1)

310-310: LGTM! Friend class declaration enables GDB server integration.

This change grants GdbClient access to Memory's private members, which is necessary for the new "sharedmem" monitor command to retrieve shared memory names from the WRAM shared memory object.

src/support/sharedmem.h (1)

52-52: LGTM! Clean getter method implementation.

The public accessor method properly exposes the shared memory name while maintaining encapsulation by returning a copy of the string.

src/core/gdb-server.cc (1)

763-772: LGTM! Well-structured monitor command implementation.

The new "sharedmem" command follows the established pattern with proper:

  • Argument validation
  • Clear usage messages
  • Error handling for unsupported types
  • Access to the shared memory name via the new getter
src/support/sharedmem-windows.cc (2)

40-40: LGTM! Proper conversion from local to member variable.

The change from local fullname variable to member m_sharedName enables persistent storage of the shared memory name while maintaining the same functionality.

Also applies to: 44-44


59-59: LGTM! Comprehensive cleanup of member variable.

Good practice to clear m_sharedName in all failure paths and the destructor, ensuring consistent state management of the shared memory name.

Also applies to: 63-63, 81-81

uint8_t* getPtr() { return m_mem; }
size_t getSize() { return m_size; }

std::string getSharedName() { return m_sharedName; }
Copy link
Member

Choose a reason for hiding this comment

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

const std::string& getSharedName() const { return m_sharedName; }

writeEscaped("Usage: sharedmem <type>");
} else {
if (words[1] == "wram") {
writeEscaped(g_emulator->m_mem->m_wramShared.getSharedName().c_str());
Copy link
Member

Choose a reason for hiding this comment

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

writeEscaped(g_emulator->m_mem->m_wramShared.getSharedName());

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/core/gdb-server.cc (3)

763-772: Consider refactoring to reduce function complexity.

While the new functionality is well-implemented, the static analysis tool correctly flags that processMonitorCommand is growing in complexity (now at 16 vs threshold of 9).

Consider extracting monitor command handlers into separate methods:

+    } else if (words[0] == "sharedmem") {
+        processSharedMemCommand(words);
     }

Then implement:

void PCSX::GdbClient::processSharedMemCommand(const std::vector<std::string>& words) {
    if (words.size() != 2) {
        writeEscaped("Usage: sharedmem <type>");
    } else {
        if (words[1] == "wram") {
            writeEscaped(g_emulator->m_mem->m_wramShared.getSharedName());
        } else {
            writeEscaped("Unknown type. Valid types: wram");
        }
    }
}

765-765: Add missing newline in usage message.

The usage message is missing a trailing newline for consistency with other error messages in the function.

-            writeEscaped("Usage: sharedmem <type>");
+            writeEscaped("Usage: sharedmem <type>\n");

770-770: Add missing newline in error message.

The error message is missing a trailing newline for consistency with other messages in the function.

-                writeEscaped("Unknown type. Valid types: wram");
+                writeEscaped("Unknown type. Valid types: wram\n");
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07e9b47 and 390ccf6.

📒 Files selected for processing (2)
  • src/core/gdb-server.cc (1 hunks)
  • src/support/sharedmem.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/support/sharedmem.h
🧰 Additional context used
🪛 GitHub Check: CodeScene Cloud Delta Analysis (main)
src/core/gdb-server.cc

[warning] 763-772: ❌ Getting worse: Complex Method
PCSX::GdbClient::processMonitorCommand increases in cyclomatic complexity from 13 to 16, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: cross-arm64
  • GitHub Check: coverage
  • GitHub Check: toolchain
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (1)
src/core/gdb-server.cc (1)

763-772: LGTM! Clean implementation of the sharedmem monitor command.

The implementation correctly validates arguments, handles the "wram" type as specified in the PR objectives, and provides appropriate error messages for invalid usage.

@nicolasnoble nicolasnoble enabled auto-merge August 7, 2025 06:45
@nicolasnoble nicolasnoble merged commit a4d6bcc into grumpycoders:main Aug 7, 2025
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants