Skip to content

Commit 3bb8050

Browse files
committed
Un-hardcode python module name.
1 parent 04fc5da commit 3bb8050

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/dbg/DbgEngContext.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <windows.h>
88
#include <DbgEng.h>
99

10+
#include <cctype>
1011
#include <string>
1112

1213
namespace PyExt::Dbg {
@@ -100,10 +101,14 @@ namespace PyExt::Dbg {
100101
name, sizeof(name), &nameSize)))
101102
continue;
102103

103-
// Match "python" prefix but not unrelated modules. python3.dll is a thin
104-
// forwarder with no useful symbols, so skip the bare "python3".
104+
// Match the versioned "pythonNNN" dll that actually carries the symbols
105+
// (python311, python314, python313t, python27, ...). Skip the bare
106+
// "python" launcher exe (no PyType_Type etc.) and the "python3.dll"
107+
// forwarder. This mirrors engextcpp's FindFirstModule("python???"),
108+
// which required digits after the prefix.
105109
std::string mod(name);
106-
if (mod.rfind("python", 0) == 0 && mod != "python3") {
110+
if (mod.rfind("python", 0) == 0 && mod != "python3"
111+
&& mod.size() > 6 && std::isdigit(static_cast<unsigned char>(mod[6]))) {
107112
std::string result = mod;
108113
result += '!';
109114
result += symbol;

test/PyExtTest/RemoteValueTest.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ TEST_CASE("RemoteValue matches the ExtRemoteTyped object model.", "[integration]
2929

3030
DbgEngContext ctx(dump.pClient.Get());
3131

32+
// The dump's Python version varies across the CI matrix (2.7, 3.11, 3.14, ...),
33+
// so the module name is resolved dynamically rather than hardcoded.
34+
auto pyTypeTypeSym = ctx.qualifyPythonSymbol("PyType_Type");
35+
REQUIRE(pyTypeTypeSym.has_value());
36+
3237
SECTION("pointerSize / evaluate / qualify")
3338
{
3439
REQUIRE(ctx.pointerSize() == 8);
3540

36-
auto addr = ctx.evaluateU64("python314!PyType_Type");
41+
auto addr = ctx.evaluateU64(*pyTypeTypeSym);
3742
REQUIRE(addr.has_value());
3843
REQUIRE(*addr != 0);
3944

@@ -44,7 +49,7 @@ TEST_CASE("RemoteValue matches the ExtRemoteTyped object model.", "[integration]
4449

4550
SECTION("scalar + field parity against the object model")
4651
{
47-
auto addrOpt = ctx.evaluateU64("python314!PyType_Type");
52+
auto addrOpt = ctx.evaluateU64(*pyTypeTypeSym);
4853
REQUIRE(addrOpt.has_value());
4954
const std::uint64_t addr = *addrOpt;
5055

@@ -67,7 +72,7 @@ TEST_CASE("RemoteValue matches the ExtRemoteTyped object model.", "[integration]
6772

6873
SECTION("typeSize via GetTypeSize (the cast-expression-site primitive)")
6974
{
70-
auto addr = ctx.evaluateU64("python314!PyType_Type");
75+
auto addr = ctx.evaluateU64(*pyTypeTypeSym);
7176
REQUIRE(addr.has_value());
7277
// PyObject header is 2 pointers on a GIL build (proven 0x10 in Phase 0).
7378
REQUIRE(RemoteValue(ctx, "PyObject", *addr).typeSize()
@@ -76,7 +81,7 @@ TEST_CASE("RemoteValue matches the ExtRemoteTyped object model.", "[integration]
7681

7782
SECTION("expected-absent field returns nullopt, does not throw")
7883
{
79-
auto addr = ctx.evaluateU64("python314!PyType_Type");
84+
auto addr = ctx.evaluateU64(*pyTypeTypeSym);
8085
REQUIRE(addr.has_value());
8186
RemoteValue rv(ctx, "_object", *addr);
8287
REQUIRE_FALSE(rv.field("field_that_does_not_exist").has_value());

0 commit comments

Comments
 (0)