Skip to content

Commit

Permalink
debugging: allow targets outside vcml modules
Browse files Browse the repository at this point in the history
  • Loading branch information
janweinstock committed Aug 8, 2024
1 parent c5e8407 commit 02a51ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
7 changes: 7 additions & 0 deletions include/vcml/debugging/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class target
virtual void define_cpureg(size_t regno, const string& name, size_t size,
size_t n, int prot = VCML_ACCESS_READ_WRITE);

virtual void update_single_stepping(bool on);

virtual bool start_basic_block_trace();
virtual bool stop_basic_block_trace();

Expand Down Expand Up @@ -134,6 +136,7 @@ class target
const char* target_name() const { return m_name.c_str(); }

target();
target(const string& name);
virtual ~target();

vector<cpureg> cpuregs() const;
Expand Down Expand Up @@ -235,12 +238,16 @@ inline bool target::is_stepping() const {

inline void target::request_singlestep(subscriber* subscr) {
lock_guard<mutex> guard(m_mtx);
if (m_steppers.empty())
update_single_stepping(true);
stl_add_unique(m_steppers, subscr);
}

inline void target::cancel_singlestep(subscriber* subscr) {
lock_guard<mutex> guard(m_mtx);
stl_remove(m_steppers, subscr);
if (m_steppers.empty())
update_single_stepping(false);
}

inline bool target::is_tracing_basic_blocks() const {
Expand Down
22 changes: 16 additions & 6 deletions src/vcml/debugging/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,19 @@ void target::define_cpureg(size_t regno, const string& name, size_t size,
newreg.host = this;
}

target::target():
static string find_name() {
module* host = hierarchy_search<module>();
VCML_ERROR_ON(!host, "debug target declared outside module");
return host->name();
}

target::target(): target(find_name()) {
// nothing to do
}

target::target(const string& name):
m_mtx(),
m_name(),
m_name(name),
m_suspendable(true),
m_running(true),
m_endian(ENDIAN_UNKNOWN),
Expand All @@ -65,10 +75,6 @@ target::target():
m_bbtracer(),
m_breakpoints(),
m_watchpoints() {
module* host = hierarchy_search<module>();
VCML_ERROR_ON(!host, "debug target declared outside module");
m_name = host->name();

if (stl_contains(s_targets, m_name))
VCML_ERROR("debug target '%s' already exists", m_name.c_str());
s_targets[m_name] = this;
Expand Down Expand Up @@ -290,6 +296,10 @@ bool target::disassemble(const range& addr, vector<disassembly>& s) {
return ptr > mem.data();
}

void target::update_single_stepping(bool on) {
// to be overloaded
}

bool target::start_basic_block_trace() {
return false; // to be overloaded
}
Expand Down

0 comments on commit 02a51ab

Please sign in to comment.