Skip to content

Commit ccb1cc5

Browse files
committed
fix: invalid type property check led to failed tests
1 parent 340382c commit ccb1cc5

File tree

2 files changed

+62
-15
lines changed

2 files changed

+62
-15
lines changed

src/debugger.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ export abstract class GenericDebuggerFacade implements IDebuggerFacade, vscode.D
553553
}
554554

555555
isScalarType(variable: IDebugVariable, type?: string) {
556+
const value = this.getValue(variable);
557+
if (value.startsWith('0x')) {
558+
return false;
559+
}
560+
556561
return builtInTypes.has(type ?? variable.type);
557562
}
558563

@@ -897,10 +902,6 @@ export class CodeLLDBDebuggerFacade extends GenericDebuggerFacade {
897902
return scope.name === 'Local';
898903
}
899904

900-
valueRepresentsStructure(value: string) {
901-
return value.startsWith('{') && value.endsWith('}');
902-
}
903-
904905
async evaluate(expression: string, frameId: number | undefined, context?: string, noReturn?: boolean): Promise<dap.EvaluateResponse> {
905906
try {
906907
context ??= 'watch';
@@ -956,6 +957,22 @@ export class CodeLLDBDebuggerFacade extends GenericDebuggerFacade {
956957

957958
return nullRegex.test(variable.value);
958959
}
960+
961+
private isPointerValue(value: string) {
962+
if (value === '<null>' || value === '<invalid address>') {
963+
return true;
964+
}
965+
966+
if (value === '0x0') {
967+
return true;
968+
}
969+
970+
if (value.startsWith('0x')) {
971+
return true;
972+
}
973+
974+
return pointerRegex.test(value);
975+
}
959976

960977
isValidPointerType(variable: IDebugVariable | dap.EvaluateResponse): boolean {
961978
if ('result' in variable) {
@@ -977,15 +994,37 @@ export class CodeLLDBDebuggerFacade extends GenericDebuggerFacade {
977994
}
978995

979996
isScalarType(variable: IDebugVariable, type?: string) {
997+
if ((type ?? variable.type).indexOf('*') !== -1) {
998+
return false;
999+
}
1000+
1001+
if ((type ?? variable.type).indexOf('[]') !== -1) {
1002+
/* flexible array member */
1003+
return false;
1004+
}
1005+
9801006
/*
9811007
* CodeLLDB displays structures in 'description', so we can use
9821008
* this info to figure out, that even if type is not builtin, it
9831009
* is actually not a struct.
9841010
* 'valueRepresentsStructure' also covers case, when 'description'
9851011
* is array - it rendered as '{1, 2, 3, ...}'.
9861012
*/
987-
return super.isScalarType(variable, type) ||
988-
!this.valueRepresentsStructure(variable.value);
1013+
if (super.isScalarType(variable, type)) {
1014+
return true;
1015+
}
1016+
1017+
const value = this.getValue(variable);
1018+
1019+
if (value.startsWith('{') && value.endsWith('}')) {
1020+
return false;
1021+
}
1022+
1023+
if (this.isPointerValue(value)) {
1024+
return false;
1025+
}
1026+
1027+
return true;
9891028
}
9901029

9911030
isValueStruct(variable: IDebugVariable, type?: string): boolean {

src/variables.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ export abstract class Variable {
12251225
type: effectiveType,
12261226
declaredType: debugVariable.type,
12271227
};
1228-
1228+
12291229
/* Value struct or scalar types are not so interesting for us */
12301230
if ( context.debug.isValueStruct(debugVariable, effectiveType)
12311231
|| context.debug.isScalarType(debugVariable, effectiveType)) {
@@ -1248,16 +1248,20 @@ export abstract class Variable {
12481248
/*
12491249
* Pointer types can be NULL or contain invalid pointers.
12501250
* cppdbg do not recognize invalid pointers, but CodeLLDB - <invalid pointer>.
1251+
*
1252+
* For such variables use special InvalidVariable, which do not
1253+
* act like RealVariable, so it prevent some potential errors.
12511254
*/
1252-
if (!context.debug.isValidPointerType(debugVariable)) {
1255+
if (!( context.debug.isValidPointerType(debugVariable)
1256+
|| context.debug.isFixedSizeArray(debugVariable))) {
12531257
/*
12541258
* We are here if got scalar type or value struct (not pointer).
12551259
* These types are not so interesting for us, so pass here to
12561260
* quickly return usual variable.
12571261
*/
12581262

12591263
if ( context.debug.isNull(debugVariable)
1260-
&& debugVariable.type.endsWith('List *')) {
1264+
&& effectiveType.endsWith('List *')) {
12611265
/*
12621266
* Empty List is NIL == NULL == '0x0' Also 'endsWith'
12631267
* covers cases like 'const List *'.
@@ -1275,7 +1279,7 @@ export abstract class Variable {
12751279
return new ListNodeVariable('List', args);
12761280
}
12771281

1278-
if (parent && dbg.isFlexibleArrayMember(debugVariable.type)) {
1282+
if (parent && dbg.isFlexibleArrayMember(effectiveType)) {
12791283
/*
12801284
* Flexible array members for now recognized as non-valid
12811285
* pointers/scalars, but we actually can handle them.
@@ -1288,7 +1292,7 @@ export abstract class Variable {
12881292
}
12891293
}
12901294

1291-
return new InvalidPointerType(args);
1295+
return new InvalidVariable(args);
12921296
}
12931297

12941298
/*
@@ -1618,7 +1622,7 @@ class ScalarVariable extends Variable {
16181622
}
16191623
}
16201624

1621-
class InvalidPointerType extends Variable {
1625+
class InvalidVariable extends Variable {
16221626
constructor(args: RealVariableArgs) {
16231627
super(args.name, args.value, args.type, args.declaredType,
16241628
args.context, args.frameId, args.parent);
@@ -1817,8 +1821,12 @@ export class RealVariable extends Variable {
18171821
if (m instanceof RealVariable) {
18181822
return m;
18191823
}
1824+
1825+
if (m instanceof InvalidVariable) {
1826+
return;
1827+
}
18201828

1821-
throw new EvaluationError(`member "${member}" is not RealVariable`);
1829+
throw new EvaluationError(`member "${member}" is neither RealVariable nor InvalidPointer`);
18221830
}
18231831

18241832
/**
@@ -2469,7 +2477,7 @@ class ExprNodeVariable extends NodeVariable {
24692477
}
24702478

24712479
const alias = await rte.getRealMember('alias');
2472-
if (alias.isValidPointer()) {
2480+
if (alias) {
24732481
const aliasColnames = await alias.getListMemberElements('colnames');
24742482

24752483
if (varattno <= aliasColnames.length) {
@@ -2534,7 +2542,7 @@ class ExprNodeVariable extends NodeVariable {
25342542
}
25352543

25362544
const eref = await rte.getRealMember('eref');
2537-
if (eref.isValidPointer()) {
2545+
if (eref) {
25382546
const erefColnames = await eref.getListMemberElements('colnames');
25392547
if (varattno <= erefColnames.length) {
25402548
const colname = erefColnames[varattno - 1];

0 commit comments

Comments
 (0)