Skip to content

Commit

Permalink
Merge branch 'stackframe-newid' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Apr 30, 2019
2 parents cb67334 + efd4d05 commit 0fcaf68
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/debug/netcoredbg/breakpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ HRESULT Breakpoints::HandleEnabled(BreakpointType &bp, Debugger *debugger, ICorD
{
DWORD threadId = 0;
IfFailRet(pThread->GetID(&threadId));
uint64_t frameId = StackFrame(threadId, 0, "").id;
uint32_t frameId = StackFrame(threadId, 0, "").id;

Variable variable;
std::string output;
Expand Down
6 changes: 3 additions & 3 deletions src/debug/netcoredbg/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class Debugger
virtual void InsertExceptionBreakpoint(const std::string &name, Breakpoint &breakpoint) = 0;
virtual HRESULT GetStackTrace(int threadId, int startFrame, int levels, std::vector<StackFrame> &stackFrames, int &totalFrames) = 0;
virtual HRESULT StepCommand(int threadId, StepType stepType) = 0;
virtual HRESULT GetScopes(uint64_t frameId, std::vector<Scope> &scopes) = 0;
virtual HRESULT GetScopes(uint32_t frameId, std::vector<Scope> &scopes) = 0;
virtual HRESULT GetVariables(uint32_t variablesReference, VariablesFilter filter, int start, int count, std::vector<Variable> &variables) = 0;
virtual int GetNamedVariables(uint32_t variablesReference) = 0;
virtual HRESULT Evaluate(uint64_t frameId, const std::string &expression, Variable &variable, std::string &output) = 0;
virtual HRESULT Evaluate(uint32_t frameId, const std::string &expression, Variable &variable, std::string &output) = 0;
virtual HRESULT SetVariable(const std::string &name, const std::string &value, uint32_t ref, std::string &output) = 0;
virtual HRESULT SetVariableByExpression(uint64_t frameId, const std::string &name, const std::string &value, std::string &output) = 0;
virtual HRESULT SetVariableByExpression(uint32_t frameId, const std::string &name, const std::string &value, std::string &output) = 0;
};

class Protocol
Expand Down
4 changes: 4 additions & 0 deletions src/debug/netcoredbg/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

static const uint16_t DEFAULT_SERVER_PORT = 4711;

std::unordered_map<uint64_t, uint32_t> StackFrameData::idStore {};
uint32_t StackFrameData::nextId = 0;
std::unordered_map<uint32_t, uint64_t> StackFrame::keyStore {};

static void print_help()
{
fprintf(stdout,
Expand Down
26 changes: 13 additions & 13 deletions src/debug/netcoredbg/manageddebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ class Variables

ValueKind valueKind;
ToRelease<ICorDebugValue> value;
uint64_t frameId;
uint32_t frameId;

VariableReference(const Variable &variable, uint64_t frameId, ToRelease<ICorDebugValue> value, ValueKind valueKind) :
VariableReference(const Variable &variable, uint32_t frameId, ToRelease<ICorDebugValue> value, ValueKind valueKind) :
variablesReference(variable.variablesReference),
namedVariables(variable.namedVariables),
indexedVariables(variable.indexedVariables),
Expand All @@ -330,7 +330,7 @@ class Variables
frameId(frameId)
{}

VariableReference(uint32_t variablesReference, uint64_t frameId, int namedVariables) :
VariableReference(uint32_t variablesReference, uint32_t frameId, int namedVariables) :
variablesReference(variablesReference),
namedVariables(namedVariables),
indexedVariables(0),
Expand All @@ -350,10 +350,10 @@ class Variables
std::unordered_map<uint32_t, VariableReference> m_variables;
uint32_t m_nextVariableReference;

void AddVariableReference(Variable &variable, uint64_t frameId, ICorDebugValue *value, ValueKind valueKind);
void AddVariableReference(Variable &variable, uint32_t frameId, ICorDebugValue *value, ValueKind valueKind);

HRESULT GetStackVariables(
uint64_t frameId,
uint32_t frameId,
ICorDebugThread *pThread,
ICorDebugFrame *pFrame,
int start,
Expand Down Expand Up @@ -388,7 +388,7 @@ class Variables
bool static_members = false);

HRESULT SetStackVariable(
uint64_t frameId,
uint32_t frameId,
ICorDebugThread *pThread,
ICorDebugFrame *pFrame,
const std::string &name,
Expand Down Expand Up @@ -431,16 +431,16 @@ class Variables
ICorDebugProcess *pProcess,
ICorDebugValue *pVariable,
const std::string &value,
uint64_t frameId,
uint32_t frameId,
std::string &output);

HRESULT GetScopes(ICorDebugProcess *pProcess, uint64_t frameId, std::vector<Scope> &scopes);
HRESULT GetScopes(ICorDebugProcess *pProcess, uint32_t frameId, std::vector<Scope> &scopes);

HRESULT Evaluate(ICorDebugProcess *pProcess, uint64_t frameId, const std::string &expression, Variable &variable, std::string &output);
HRESULT Evaluate(ICorDebugProcess *pProcess, uint32_t frameId, const std::string &expression, Variable &variable, std::string &output);

HRESULT GetValueByExpression(
ICorDebugProcess *pProcess,
uint64_t frameId,
uint32_t frameId,
const std::string &expression,
ICorDebugValue **ppResult);

Expand Down Expand Up @@ -549,10 +549,10 @@ class ManagedDebugger : public Debugger
void InsertExceptionBreakpoint(const std::string &name, Breakpoint &breakpoint) override;
HRESULT GetStackTrace(int threadId, int startFrame, int levels, std::vector<StackFrame> &stackFrames, int &totalFrames) override;
HRESULT StepCommand(int threadId, StepType stepType) override;
HRESULT GetScopes(uint64_t frameId, std::vector<Scope> &scopes) override;
HRESULT GetScopes(uint32_t frameId, std::vector<Scope> &scopes) override;
HRESULT GetVariables(uint32_t variablesReference, VariablesFilter filter, int start, int count, std::vector<Variable> &variables) override;
int GetNamedVariables(uint32_t variablesReference) override;
HRESULT Evaluate(uint64_t frameId, const std::string &expression, Variable &variable, std::string &output) override;
HRESULT Evaluate(uint32_t frameId, const std::string &expression, Variable &variable, std::string &output) override;
HRESULT SetVariable(const std::string &name, const std::string &value, uint32_t ref, std::string &output) override;
HRESULT SetVariableByExpression(uint64_t frameId, const std::string &expression, const std::string &value, std::string &output) override;
HRESULT SetVariableByExpression(uint32_t frameId, const std::string &expression, const std::string &value, std::string &output) override;
};
4 changes: 2 additions & 2 deletions src/debug/netcoredbg/miprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ HRESULT MIProtocol::CreateVar(int threadId, int level, const std::string &varobj
{
HRESULT Status;

uint64_t frameId = StackFrame(threadId, level, "").id;
uint32_t frameId = StackFrame(threadId, level, "").id;

Variable variable;
IfFailRet(m_debugger->Evaluate(frameId, expression, variable, output));
Expand Down Expand Up @@ -1129,7 +1129,7 @@ HRESULT MIProtocol::HandleCommand(std::string command,

int threadId = GetIntArg(args, "--thread", m_debugger->GetLastStoppedThreadId());
int level = GetIntArg(args, "--frame", 0);
uint64_t frameId = StackFrame(threadId, level, "").id;
uint32_t frameId = StackFrame(threadId, level, "").id;

Variable variable;
IfFailRet(FindVar(varName, variable));
Expand Down
39 changes: 32 additions & 7 deletions src/debug/netcoredbg/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <string>
#include <unordered_map>
#include <vector>
#include "platform.h"

Expand Down Expand Up @@ -38,9 +39,33 @@ struct ClrAddr
bool IsNull() const { return methodToken == 0; }
};

struct StackFrameData
{
static std::unordered_map<uint64_t, uint32_t> idStore;
static uint32_t nextId;
int id;
uint64_t key;

StackFrameData(int threadId, uint32_t level)
{
key = threadId;
key <<= 32;
key |= level;
if (idStore.find(key) == idStore.end())
{
StackFrameData::nextId++;
idStore[key] = StackFrameData::nextId;
}

id = idStore[key];
}
};

struct StackFrame
{
uint64_t id; // (threadId << 32) | level
static std::unordered_map<uint32_t, uint64_t> keyStore;

uint32_t id;
std::string name;
Source source;
int line;
Expand All @@ -58,15 +83,15 @@ struct StackFrame
StackFrame(int threadId, uint32_t level, std::string name) :
name(name), line(0), column(0), endLine(0), endColumn(0), addr(0)
{
id = threadId;
id <<= 32;
id |= level;
StackFrameData data = StackFrameData(threadId, level);
id = data.id;
keyStore[id] = data.key;
}

StackFrame(uint64_t id) : id(id), line(0), column(0), endLine(0), endColumn(0), addr(0) {}
StackFrame(uint32_t id) : id(id), line(0), column(0), endLine(0), endColumn(0), addr(0) {}

uint32_t GetLevel() const { return id & 0xFFFFFFFFul; }
int GetThreadId() const { return id >> 32; }
uint32_t GetLevel() const { return keyStore[id] & 0xFFFFFFFFul; }
int GetThreadId() const { return keyStore[id] >> 32; }
};

struct Breakpoint
Expand Down
20 changes: 10 additions & 10 deletions src/debug/netcoredbg/variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ HRESULT Variables::GetVariables(
return S_OK;
}

void Variables::AddVariableReference(Variable &variable, uint64_t frameId, ICorDebugValue *value, ValueKind valueKind)
void Variables::AddVariableReference(Variable &variable, uint32_t frameId, ICorDebugValue *value, ValueKind valueKind)
{
unsigned int numChild = 0;
GetNumChild(value, numChild, valueKind == ValueIsClass);
Expand All @@ -220,7 +220,7 @@ void Variables::AddVariableReference(Variable &variable, uint64_t frameId, ICorD
}

HRESULT Variables::GetStackVariables(
uint64_t frameId,
uint32_t frameId,
ICorDebugThread *pThread,
ICorDebugFrame *pFrame,
int start,
Expand Down Expand Up @@ -271,14 +271,14 @@ HRESULT Variables::GetStackVariables(
return S_OK;
}

HRESULT ManagedDebugger::GetScopes(uint64_t frameId, std::vector<Scope> &scopes)
HRESULT ManagedDebugger::GetScopes(uint32_t frameId, std::vector<Scope> &scopes)
{
LogFuncEntry();

return m_variables.GetScopes(m_pProcess, frameId, scopes);
}

HRESULT Variables::GetScopes(ICorDebugProcess *pProcess, uint64_t frameId, std::vector<Scope> &scopes)
HRESULT Variables::GetScopes(ICorDebugProcess *pProcess, uint32_t frameId, std::vector<Scope> &scopes)
{
if (pProcess == nullptr)
return E_FAIL;
Expand Down Expand Up @@ -406,7 +406,7 @@ HRESULT Variables::GetChildren(
return S_OK;
}

HRESULT ManagedDebugger::Evaluate(uint64_t frameId, const std::string &expression, Variable &variable, std::string &output)
HRESULT ManagedDebugger::Evaluate(uint32_t frameId, const std::string &expression, Variable &variable, std::string &output)
{
LogFuncEntry();

Expand All @@ -415,7 +415,7 @@ HRESULT ManagedDebugger::Evaluate(uint64_t frameId, const std::string &expressio

HRESULT Variables::Evaluate(
ICorDebugProcess *pProcess,
uint64_t frameId,
uint32_t frameId,
const std::string &expression,
Variable &variable,
std::string &output)
Expand Down Expand Up @@ -587,7 +587,7 @@ HRESULT Variables::SetVariable(
}

HRESULT Variables::SetStackVariable(
uint64_t frameId,
uint32_t frameId,
ICorDebugThread *pThread,
ICorDebugFrame *pFrame,
const std::string &name,
Expand Down Expand Up @@ -657,7 +657,7 @@ HRESULT Variables::SetChild(
}

HRESULT ManagedDebugger::SetVariableByExpression(
uint64_t frameId,
uint32_t frameId,
const std::string &expression,
const std::string &value,
std::string &output)
Expand All @@ -669,7 +669,7 @@ HRESULT ManagedDebugger::SetVariableByExpression(
return m_variables.SetVariable(m_pProcess, pResultValue, value, frameId, output);
}

HRESULT Variables::GetValueByExpression(ICorDebugProcess *pProcess, uint64_t frameId, const std::string &expression,
HRESULT Variables::GetValueByExpression(ICorDebugProcess *pProcess, uint32_t frameId, const std::string &expression,
ICorDebugValue **ppResult)
{
if (pProcess == nullptr)
Expand All @@ -690,7 +690,7 @@ HRESULT Variables::SetVariable(
ICorDebugProcess *pProcess,
ICorDebugValue *pVariable,
const std::string &value,
uint64_t frameId,
uint32_t frameId,
std::string &output)
{
HRESULT Status;
Expand Down
2 changes: 1 addition & 1 deletion src/debug/netcoredbg/vscodeprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ HRESULT VSCodeProtocol::HandleCommand(const std::string &command, const json &ar
{ "evaluate", [this](const json &arguments, json &body){
HRESULT Status;
std::string expression = arguments.at("expression");
uint64_t frameId;
uint32_t frameId;
auto frameIdIter = arguments.find("frameId");
if (frameIdIter == arguments.end())
{
Expand Down

0 comments on commit 0fcaf68

Please sign in to comment.