Skip to content

Commit

Permalink
debugger: nul-terminated string format improvements
Browse files Browse the repository at this point in the history
* use one argument instead of two
* use width to control maximum length
* add debugger help text
  • Loading branch information
pmackinlay committed Mar 12, 2024
1 parent 7e3b98d commit 1bdfa86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/emu/debug/debugcmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,33 +573,35 @@ bool debugger_commands::mini_printf(std::ostream &stream, const std::vector<std:
break;

case 's':
if ((param + 1) < params.size())
{
address_space *space, *tspace;
std::string s;

if (m_console.validate_device_space_parameter(params[param + 0], -1, space) && m_console.validate_number_parameter(params[param + 1], number))
address_space *space;
if (param < params.size() && m_console.validate_target_address_parameter(params[param++], -1, space, number))
{
address_space *tspace;
std::string s;

for (u32 address = u32(number), taddress; space->device().memory().translate(space->spacenum(), device_memory_interface::TR_READ, taddress = address, tspace); address++)
{
u8 const data = tspace->read_byte(taddress);

if (data)
s += data;
else
if (!data)
break;

s += data;

if (width == 1)
break;
else if (width)
width--;
}

util::stream_format(stream, "%*s", width, s);
param += 2;
util::stream_format(stream, "%s", s);
}
else
{
m_console.printf("Not enough parameters for format!\n");
return false;
}
else
{
m_console.printf("Not enough parameters for format!\n");
return false;
}
}
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/emu/debug/debughlp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ const help_item f_static_help_list[] =
"\n"
" %[0][<n>]d -- prints <item> as a decimal value with optional digit count and zero-fill\n"
" %[0][<n>]x -- prints <item> as a hexadecimal value with optional digit count and zero-fill\n"
" %[<n>]s -- prints all or up to <n> non-nul bytes from address and address space given by <item>\n"
"\n"
"All remaining formatting options are ignored. Use %% together to output a % character. Multiple "
"lines can be printed by embedding a \\n in the text.\n"
Expand All @@ -383,6 +384,7 @@ const help_item f_static_help_list[] =
"\n"
" %[0][<n>]d -- logs <item> as a decimal value with optional digit count and zero-fill\n"
" %[0][<n>]x -- logs <item> as a hexadecimal value with optional digit count and zero-fill\n"
" %[<n>]s -- logs all or up to <n> non-nul bytes from address and address space given by <item>\n"
"\n"
"All remaining formatting options are ignored. Use %% together to output a % character. Multiple "
"lines can be printed by embedding a \\n in the text.\n"
Expand Down

0 comments on commit 1bdfa86

Please sign in to comment.