Skip to content

Commit 6f9dcbf

Browse files
committed
chore: check for garbage in pointer validity check for cppdbg
CodeLLDB tests pointer to contain garbage and it renders <invalid pointer> in such case, but cppdbg does not do this, but it's a very good feature, so add such manual check - compare with too small pointer value.
1 parent b5a8b75 commit 6f9dcbf

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/debugger.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,39 @@ export class CppDbgDebuggerFacade extends GenericDebuggerFacade {
650650
*/
651651
return response.result.startsWith('-var-create');
652652
}
653+
654+
private isNullInternal(value: string) {
655+
return value === '0x0';
656+
}
653657

654658
isNull(variable: IDebugVariable | dap.EvaluateResponse) {
655-
return this.getValue(variable) === '0x0';
659+
return this.isNullInternal(this.getValue(variable));
656660
}
657661

658662
isValidPointerType(variable: IDebugVariable | dap.EvaluateResponse) {
659-
/* Check isNull first, because lots of variables can be NULL, i.e. Bitmapset */
660-
return !this.isNull(variable) && pointerRegex.test(this.getValue(variable));
663+
/* Now check that value looks like pointer - otherwise it is not pointer */
664+
const pointer = this.getValue(variable);
665+
if (!(pointer.startsWith('0x') && pointerRegex.test(pointer))) {
666+
return false;
667+
}
668+
669+
/* Check isNull first, because lots of variables can be NULL */
670+
if (this.isNullInternal(pointer)) {
671+
return false;
672+
}
673+
674+
/*
675+
* Even if this is pointer it can have garbage. To check this
676+
* compare with some definitely impossible pointer value.
677+
* This can happen not only for garbage, but also when integer
678+
* is assigned to pointer type.
679+
*/
680+
const ptrNumber = Number(pointer);
681+
if (Number.isNaN(ptrNumber) || ptrNumber < 0x10000) {
682+
return false;
683+
}
684+
685+
return true;
661686
}
662687

663688
isValueStruct(variable: IDebugVariable, type?: string) {

0 commit comments

Comments
 (0)