Skip to content

Commit ee1b2f6

Browse files
committed
fix: invalid typedef logic for Node vars (MemoryContext main reason)
1 parent 730d4bb commit ee1b2f6

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export function getDefaultNodeTags(): string[] {
337337
'MemoizePath',
338338
'MemoizeState',
339339
'MemoryContext',
340+
'MemoryContextData',
340341
'MergeAction',
341342
'MergeActionState',
342343
'MergeAppend',

src/utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,13 @@ export function substituteStructName(type: string, target: string) {
102102
* @param variable Variable to test
103103
* @returns true if variable is raw struct
104104
*/
105-
export function isRawStruct(variable: { parent?: {}, value: string, type: string }) {
105+
export function isRawStruct(type: string, value: string) {
106106
/*
107107
* Check that variable is plain struct - not pointer.
108108
* Figured out - top level variables has {...} in value, but
109109
* struct members are empty strings. (For raw structs).
110110
*/
111-
return variable.parent instanceof VariablesRoot
112-
? variable.value === '{...}'
113-
: variable.value === '' && !variable.type.endsWith('[]');
111+
return value === '{...}' || (value === '' && !type.endsWith('[]'));
114112
}
115113

116114
export function isFixedSizeArray(variable: {parent?: {}, type: string, value: string}): boolean {

src/variables.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,18 @@ export class NodeVarRegistry {
106106
let typeName = utils.getStructNameFromType(type);
107107

108108
/* [const] [struct] NAME * */
109-
return this.nodeTags.has(typeName) && utils.getPointersCount(type) === 1
109+
if (this.nodeTags.has(typeName) && utils.getPointersCount(type) === 1) {
110+
return true;
111+
}
112+
113+
const alias = this.aliases.get(typeName);
114+
if (!alias) {
115+
return false;
116+
}
117+
118+
type = type.replace(typeName, alias);
119+
typeName = utils.getStructNameFromType(type);
120+
return this.nodeTags.has(typeName) && utils.getPointersCount(type) === 1;
110121
}
111122

112123
/**
@@ -432,7 +443,7 @@ export abstract class Variable {
432443
}
433444

434445
/* Embedded or top level structs */
435-
if (utils.isRawStruct(this)) {
446+
if (utils.isRawStruct(this.type, this.value)) {
436447
return true;
437448
}
438449

@@ -508,7 +519,9 @@ export abstract class Variable {
508519
context,
509520
logger,
510521
};
511-
if (utils.isRawStruct(debugVariable) ||
522+
523+
const realType = Variable.getRealType(debugVariable, context);
524+
if (utils.isRawStruct(realType, debugVariable.value) ||
512525
!utils.isValidPointer(debugVariable.value)) {
513526
if (utils.isNull(debugVariable.value) && debugVariable.type === 'List *') {
514527
/* Empty List is NIL == NULL == '0x0' */
@@ -518,8 +531,6 @@ export abstract class Variable {
518531
return new RealVariable(args);
519532
}
520533

521-
const realType = Variable.getRealType(debugVariable, context);
522-
523534
/*
524535
* PostgreSQL versions prior 16 do not have Bitmapset Node.
525536
* So handle Bitmapset (with Relids) here.
@@ -531,7 +542,7 @@ export abstract class Variable {
531542
/* NodeTag variables: Node, List, Bitmapset etc.. */
532543
if (context.nodeVarRegistry.isNodeVar(realType)) {
533544
const nodeTagVar = await NodeVariable.create(debugVariable, frameId,
534-
context, logger, parent);
545+
context, logger, parent);
535546
if (nodeTagVar) {
536547
return nodeTagVar;
537548
}
@@ -1052,7 +1063,7 @@ export class NodeVariable extends RealVariable {
10521063
*
10531064
* @example `OpExpr *' was `Node *'
10541065
*/
1055-
realType: string | undefined;
1066+
realType?: string;
10561067

10571068
constructor(realNodeTag: string, args: RealVariableArgs) {
10581069
super(args);
@@ -1068,12 +1079,13 @@ export class NodeVariable extends RealVariable {
10681079
/*
10691080
* Also try find aliases for some NodeTags
10701081
*/
1071-
const alias = this.context.nodeVarRegistry.aliases.get(this.realNodeTag);
1082+
let type = this.type;
1083+
const alias = this.context.nodeVarRegistry.aliases.get(tagFromType);
10721084
if (alias) {
1073-
return utils.substituteStructName(this.type, alias);
1085+
type = utils.substituteStructName(type, alias);
10741086
}
10751087

1076-
return utils.substituteStructName(this.type, this.realNodeTag);
1088+
return utils.substituteStructName(type, this.realNodeTag);
10771089
}
10781090

10791091
getRealType(): string {
@@ -1146,7 +1158,7 @@ export class NodeVariable extends RealVariable {
11461158
* We should substitute current type with target, because
11471159
* there may be qualifiers such `struct' or `const'
11481160
*/
1149-
const resultType = utils.substituteStructName(this.type, tag);
1161+
const resultType = utils.substituteStructName(this.getRealType(), tag);
11501162
return await this.castToType(resultType);
11511163
}
11521164

@@ -1216,7 +1228,7 @@ export class NodeVariable extends RealVariable {
12161228
context: ExecContext, logger: utils.ILogger,
12171229
parent?: Variable): Promise<NodeVariable | undefined> {
12181230
const getRealNodeTag = async () => {
1219-
const nodeTagExpression = `((Node*)(${variable.evaluateName}))->type`;
1231+
const nodeTagExpression = `((Node*)(${variable.value}))->type`;
12201232
const response = await context.debug.evaluate(nodeTagExpression, frameId);
12211233
let realTag = response.result?.replace('T_', '');
12221234
if (!this.isValidNodeTag(realTag)) {

0 commit comments

Comments
 (0)