summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/debug/debugcmd.cpp
diff options
context:
space:
mode:
author hap <happppp@users.noreply.github.com>2025-06-11 19:00:29 +0200
committer hap <happppp@users.noreply.github.com>2025-06-11 19:00:39 +0200
commit4c6af4121b47d5139263cc97b0d9c0b3d909b438 (patch)
treeaafe4f98546b83cd1b1ccc6d3b721492b20e60e8 /src/emu/debug/debugcmd.cpp
parent16f4a6bbbdb7f0fe8d5627b086da0633aaf818ca (diff)
debugcmd: no need to try to convert string_view to const char*, fix possible nullptr access
Diffstat (limited to 'src/emu/debug/debugcmd.cpp')
-rw-r--r--src/emu/debug/debugcmd.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/emu/debug/debugcmd.cpp b/src/emu/debug/debugcmd.cpp
index 76a6053477f..cded76abf7a 100644
--- a/src/emu/debug/debugcmd.cpp
+++ b/src/emu/debug/debugcmd.cpp
@@ -452,13 +452,13 @@ void debugger_commands::execute_help(const std::vector<std::string_view> &params
void debugger_commands::execute_print(const std::vector<std::string_view> &params)
{
- /* validate the other parameters */
+ // validate the other parameters
u64 values[MAX_COMMAND_PARAMS];
for (int i = 0; i < params.size(); i++)
if (!m_console.validate_number_parameter(params[i], values[i]))
return;
- /* then print each one */
+ // then print each one
for (int i = 0; i < params.size(); i++)
m_console.printf("%X", values[i]);
m_console.printf("\n");
@@ -680,7 +680,7 @@ void debugger_commands::execute_index_command(std::vector<std::string_view> cons
void debugger_commands::execute_printf(const std::vector<std::string_view> &params)
{
- /* then do a printf */
+ // then do a printf
std::ostringstream buffer;
if (mini_printf(buffer, params))
m_console.printf("%s\n", std::move(buffer).str());
@@ -693,7 +693,7 @@ void debugger_commands::execute_printf(const std::vector<std::string_view> &para
void debugger_commands::execute_logerror(const std::vector<std::string_view> &params)
{
- /* then do a printf */
+ // then do a printf
std::ostringstream buffer;
if (mini_printf(buffer, params))
m_machine.logerror("%s", std::move(buffer).str());
@@ -706,7 +706,7 @@ void debugger_commands::execute_logerror(const std::vector<std::string_view> &pa
void debugger_commands::execute_tracelog(const std::vector<std::string_view> &params)
{
- /* then do a printf */
+ // then do a printf
std::ostringstream buffer;
if (mini_printf(buffer, params))
m_console.get_visible_cpu()->debug()->trace_printf("%s", std::move(buffer).str());
@@ -789,7 +789,7 @@ void debugger_commands::execute_do(const std::vector<std::string_view> &params)
void debugger_commands::execute_step(const std::vector<std::string_view> &params)
{
- /* if we have a parameter, use it */
+ // if we have a parameter, use it
u64 steps = 1;
if (params.size() > 0 && !m_console.validate_number_parameter(params[0], steps))
return;
@@ -804,7 +804,7 @@ void debugger_commands::execute_step(const std::vector<std::string_view> &params
void debugger_commands::execute_over(const std::vector<std::string_view> &params)
{
- /* if we have a parameter, use it */
+ // if we have a parameter, use it
u64 steps = 1;
if (params.size() > 0 && !m_console.validate_number_parameter(params[0], steps))
return;
@@ -831,7 +831,7 @@ void debugger_commands::execute_go(const std::vector<std::string_view> &params)
{
u64 addr = ~0;
- /* if we have a parameter, use it instead */
+ // if we have a parameter, use it instead
if (params.size() > 0 && !m_console.validate_number_parameter(params[0], addr))
return;
@@ -858,7 +858,7 @@ void debugger_commands::execute_go_interrupt(const std::vector<std::string_view>
{
u64 irqline = -1;
- /* if we have a parameter, use it instead */
+ // if we have a parameter, use it instead
if (params.size() > 0 && !m_console.validate_number_parameter(params[0], irqline))
return;
@@ -873,7 +873,7 @@ void debugger_commands::execute_go_exception(const std::vector<std::string_view>
{
u64 exception = -1;
- /* if we have a parameter, use it instead */
+ // if we have a parameter, use it instead
if (params.size() > 0 && !m_console.validate_number_parameter(params[0], exception))
return;
@@ -893,7 +893,7 @@ void debugger_commands::execute_go_time(const std::vector<std::string_view> &par
{
u64 milliseconds = -1;
- /* if we have a parameter, use it instead */
+ // if we have a parameter, use it instead
if (params.size() > 0 && !m_console.validate_number_parameter(params[0], milliseconds))
return;
@@ -2119,7 +2119,7 @@ void debugger_commands::execute_saveregion(const std::vector<std::string_view> &
if ((length <= 0) || ((length + offset) >= region->bytes()))
length = region->bytes() - offset;
- /* open the file */
+ // open the file
std::string const filename(params[0]);
FILE *f = fopen(filename.c_str(), "wb");
if (!f)
@@ -3434,7 +3434,7 @@ void debugger_commands::execute_dasm(const std::vector<std::string_view> &params
offset = next_offset;
}
- /* write the data */
+ // write the data
std::string fname(params[0]);
std::ofstream f(fname);
if (!f.good())
@@ -3749,14 +3749,14 @@ void debugger_commands::execute_pcatmem(int spacenum, const std::vector<std::str
void debugger_commands::execute_snap(const std::vector<std::string_view> &params)
{
- /* if no params, use the default behavior */
+ // if no params, use the default behavior
if (params.empty())
{
m_machine.video().save_active_screen_snapshots();
m_console.printf("Saved snapshot\n");
}
- /* otherwise, we have to open the file ourselves */
+ // otherwise, we have to open the file ourselves
else
{
u64 scrnum = 0;
@@ -3909,16 +3909,16 @@ void debugger_commands::execute_memdump(const std::vector<std::string_view> &par
void debugger_commands::execute_symlist(const std::vector<std::string_view> &params)
{
- // Default to CPU "0" if none specified
- const char * cpuname = (params.empty()) ? "0" : params[0].cbegin();
device_t *cpu = nullptr;
symbol_table *symtable;
- if (!m_console.validate_cpu_parameter(cpuname, cpu))
+
+ // default to CPU "0" if none specified
+ if (!m_console.validate_cpu_parameter(params.empty() ? "0" : params[0], cpu))
{
if (!params.empty())
- return; // Explicitly specified cpu is invalid
+ return; // explicitly specified CPU is invalid
- // Somehow cpu "0" is invalid, so just stick with global symbol table
+ // somehow CPU "0" is invalid, so just stick with global symbol table
symtable = &m_machine.debugger().cpu().global_symtable();
}
else
@@ -3926,10 +3926,13 @@ void debugger_commands::execute_symlist(const std::vector<std::string_view> &par
symtable = &cpu->debug()->symtable();
}
- // Traverse symbol_table parent chain, printing each table's symbols in its own block
+ // unknown tag if CPU is invalid
+ const char *cpu_tag = cpu ? cpu->tag() : ":?";
+
+ // traverse symbol_table parent chain, printing each table's symbols in its own block
for (; symtable != nullptr; symtable = symtable->parent())
{
- // Skip globals if user explicitly requested CPU
+ // skip globals if user explicitly requested CPU
if (symtable->type() == symbol_table::BUILTIN_GLOBALS && !params.empty())
continue;
@@ -3938,17 +3941,17 @@ void debugger_commands::execute_symlist(const std::vector<std::string_view> &par
std::vector<const char *> namelist;
- // Print heading for table
+ // print heading for table
switch (symtable->type())
{
case symbol_table::CPU_STATE:
- m_console.printf("\n**** CPU '%s' symbols ****\n", cpu->tag());
+ m_console.printf("\n**** CPU '%s' symbols ****\n", cpu_tag);
break;
case symbol_table::BUILTIN_GLOBALS:
m_console.printf("\n**** Global symbols ****\n");
break;
default:
- assert (!"Unrecognized symbol table type");
+ assert(!"Unrecognized symbol table type");
}
// gather names for all relevant symbols