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

Compilation Fails: Missing Members in 'SourcePawn' namespace #2

Open
NullExir opened this issue Jan 5, 2025 · 7 comments
Open

Compilation Fails: Missing Members in 'SourcePawn' namespace #2

NullExir opened this issue Jan 5, 2025 · 7 comments

Comments

@NullExir
Copy link

NullExir commented Jan 5, 2025

Description

Hi, the compiler will complain about missing members of the SourcePawn namespace, here's the full output of the build process using clang-14.

build.log

Compiler and OS

clang version 14.0.0
gcc version 11.4.0
Linux 5.15.153.1-microsoft-standard-WSL2

Steps to reproduce

Since the last commit time of the extension is dated at around 5 years ago, I've tried to find the relevant commit that modified some of the namespace's members, by searching for the some of missing members in the sourcepawn git tree.

Unfortunately returned no results (which is very confusing), here's what I've tried

git clone --recurse-submodules https://github.com/alliedmodders/sourcemod
cd sourcemod
git grep --recurse-submodules -rni \( -e ISymbolType -e IDebugSymbol \) $(git rev-list --all)
@peace-maker
Copy link
Owner

This extension requires more changes to the sourcepawn VM which I never got around to polish up to get them upstreamed.

https://github.com/peace-maker/sourcepawn/tree/debug_api_symbols

Sorry for wasting your time, I'll look into rebasing the branch on the latest vm so you can test at least.

@peace-maker
Copy link
Owner

I updated the IDebugSymbol changes on top of the latest SourcePawn VM now and also finally opened a pull request to enable that debugger API in the VM from sourcemod.

Some bugs in the present part of the debugger API in the VM were discovered too during this, so thank you for poking :D

If you really want to test this extension, you'll have to build sourcemod and sourcepawn with the above changes yourself:

git clone --branch enable_debugging_api --recurse-submodules https://github.com/peace-maker/sourcemod sourcemod_debugger
cd sourcemod_debugger/sourcepawn
git remote add peace-maker https://github.com/peace-maker/sourcepawn
git fetch peace-maker
git switch debug_api_symbols

Then build sourcemod for your game as usual as well as this extension with configure.py --sm-path pointing to the sourcemod_debugger folder. Make sure to set the "EnableLineDebugging" option in sourcemod's core.cfg to "yes".

Then you can start a debugging session like:

sm debug start basechat
[SM] Pausing plugin Basic Chat for debugging. Will halt on next instruction.
sm_say lol
STOP at line 156 in basechat.sp in Command_SmSay        frame: 1
dbg> n
STOP at line 158 in basechat.sp in Command_SmSay        frame: 1
dbg>
STOP at line 164 in basechat.sp in Command_SmSay        frame: 1
dbg>
STOP at line 165 in basechat.sp in Command_SmSay        frame: 1
dbg>
STOP at line 167 in basechat.sp in Command_SmSay        frame: 1
dbg> print
loc     <  0x5454>      char text[192]  "lol"
arg     <  0x5468>      int args        1
arg     <  0x5464>      int client      0
dbg> quit
Clearing all breakpoints. Running normally.
L 01/05/2025 - 21:11:40: [basechat.smx] "Console<0><Console><Console>" triggered sm_say (text lol)

I'd love to hear your feedback if you end up trying it.

@NullExir
Copy link
Author

NullExir commented Jan 6, 2025

Many thanks for the quick response and fix. I'm currently trying to build your fork, and will give you some feedback!.

@peace-maker
Copy link
Owner

I've added builds through CI, check out the latest artifacts from the latest run in the Actions tab.

@NullExir
Copy link
Author

NullExir commented Jan 10, 2025

Thanks for the Artifacts, I'm currently testing out the debugger with a simple test plugin, here's some feedback.

Issues

  • the command BREAK name:n causes the server to crash, with the following error:

    terminate called after throwing an instance of 'std::logic_error'
    what(): basic_string::_M_construct null not valid

  • WATCHPOINT doesn't work (shows ?) for:

    • local vars
    • global vars
    • global array vars
    • However it works correctly for local arrays
  • PRINT:

    • shows random (garbage?) values for global arrays
    • shows ? for multidimensional arrays

Demo plugin

This is my way to trigger the BP

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

int g_nFoo = 0;
int g_aFoo[2] = {0};

public void OnPluginStart()
{
    TriggerBp();
}

void TriggerBp()
{
    RegServerCmd("bp", Command_Bp, "Trigger the sp-dbg.ext BP");
}
public Action Command_Bp(int args)
{
    // Testing local variables
    int nFoo = 6;
    float fFoo = 55.2;
    
    g_nFoo = 6;
    
    // Testing local arrays
    int aFoo[2] = {0};
    aFoo[1] = 5;
    
    // multidimensional arrays
    // Debugger: doesn't print the array variable with "print"
    int aFooMult[1][1] = { {0} };
    aFooMult[0][0] = 44;
    /** 
      dbg> print aFooMult[0][0]
      loc     <  0x49b4>      aFooMult[0][0]  ?
    */
    
    // Suppress compiler warrning "symbol is assigned a value that is never used"
    PrintToServer("nFoo = %d, g_nFoo = %d, fFoo = %.1f", nFoo, g_nFoo, fFoo);

    return Plugin_Handled;
}

Nest loops will prevent the debugger from printing any local variables, Example:

int aFoo[1][2] = { {0, ...} };
for(int i = 0; i < sizeof(aFoo); i++)
{
    // Debugger: adding `sizeof(aFoo[])` will trigger the disappearance of the stack variables
    for(int j = 0; j < sizeof(aFoo[]); j++)
    {
        aFoo[i][j] = GetRandomInt(0, 10); // fill the each element in the array with random values
        PrintToServer("aFoo[%d][%d] = %d", i, j, aFoo[i][j]);
    }
}

Workflow

sm plugins reload temp/sp_dbg_test.smx
alias "d" "sm debug start temp/sp_dbg_test.smx;bp"
d

@peace-maker
Copy link
Owner

Multi-dimensional arrays aren't implemented yet, so that is expected.

// Not supported..
else {
fputs("(multi-dimensional array)", stdout);
}

Global arrays showing garbage seems to be a problem caused by the array rework for newer plugins. The array dereferencing has to consider the new direct array behavior.

https://github.com/alliedmodders/sourcepawn/blob/0fd19ef0eb99a76f6c985cc97c63f7ce43b81301/include/sp_vm_api.h#L584-L600

I've fixed the crash on break name:n and printing values of watched variables. The other problems appear to be caused by spcomp not emitting debug symbols for the other variables. Checking the .dbg.methods section for the Command_Bp function doesn't include any local variables except for i and j for me. Maybe they get optimized out since they're not reassigned?
https://peace-maker.github.io/sourcepawn-disassembler-web/

@NullExir
Copy link
Author

NullExir commented Jan 11, 2025

Maybe they get optimized out since they're not reassigned?

I assume that you already figured out, based on the issue you've mentioned/created

Multi-dimensional arrays aren't implemented yet, so that is expected.

Global arrays showing garbage seems to be a problem caused by alliedmodders/sourcepawn#463 for newer plugins. The array dereferencing has to consider the new direct array behavior.

Do you have any plan to address the issues?, global arrays are used a lot in many plugins, tracking their content would really help out with debugging plugins.

Either way appreciate all the work!

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