MCPcopy Create free account
hub / github.com/WebFreak001/code-debug / variablesRequest

Method variablesRequest

src/mibase.ts:417–634  ·  view source on GitHub ↗
(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments)

Source from the content-addressed store, hash-verified

415 }
416
417 protected async variablesRequest(response: DebugProtocol.VariablesResponse, args: DebugProtocol.VariablesArguments): Promise<void> {
418 const variables: DebugProtocol.Variable[] = [];
419 const id: VariableScope | string | VariableObject | ExtendedVariable = this.variableHandles.get(args.variablesReference);
420
421 const createVariable = (arg, options?) => {
422 if (options)
423 return this.variableHandles.create(new ExtendedVariable(arg, options));
424 else
425 return this.variableHandles.create(arg);
426 };
427
428 const findOrCreateVariable = (varObj: VariableObject): number => {
429 let id: number;
430 if (this.variableHandlesReverse.hasOwnProperty(varObj.name)) {
431 id = this.variableHandlesReverse[varObj.name];
432 } else {
433 id = createVariable(varObj);
434 this.variableHandlesReverse[varObj.name] = id;
435 }
436 return varObj.isCompound() ? id : 0;
437 };
438
439 if (id instanceof VariableScope) {
440 try {
441 if (id.name == "Registers") {
442 const registers = await this.miDebugger.getRegisters();
443 for (const reg of registers) {
444 variables.push({
445 name: reg.name,
446 value: reg.valueStr,
447 variablesReference: 0
448 });
449 }
450 } else {
451 const stack: Variable[] = await this.miDebugger.getStackVariables(id.threadId, id.level);
452 for (const variable of stack) {
453 if (this.useVarObjects) {
454 try {
455 const varObjName = VariableScope.variableName(args.variablesReference, variable.name);
456 let varObj: VariableObject;
457 try {
458 const changes = await this.miDebugger.varUpdate(varObjName);
459 const changelist = changes.result("changelist");
460 changelist.forEach((change) => {
461 const name = MINode.valueOf(change, "name");
462 const vId = this.variableHandlesReverse[name];
463 const v = this.variableHandles.get(vId) as any;
464 v.applyChanges(change);
465 });
466 const varId = this.variableHandlesReverse[varObjName];
467 varObj = this.variableHandles.get(varId) as any;
468 } catch (err) {
469 if (err instanceof MIError && err.message == "Variable object not found") {
470 varObj = await this.miDebugger.varCreate(variable.name, varObjName);
471 const varId = findOrCreateVariable(varObj);
472 varObj.exp = variable.name;
473 varObj.id = varId;
474 } else {

Callers

nothing calls this directly

Calls 13

expandValueFunction · 0.90
prettyStringArrayFunction · 0.85
getRegistersMethod · 0.80
variableNameMethod · 0.80
varUpdateMethod · 0.80
resultMethod · 0.80
valueOfMethod · 0.80
applyChangesMethod · 0.80
varCreateMethod · 0.80
toProtocolVariableMethod · 0.80
varListChildrenMethod · 0.80
getStackVariablesMethod · 0.65

Tested by

no test coverage detected