Merge pull request #2926 from vadosnaprimer/debughlp_html

Command to print all debugger help to html file
This commit is contained in:
R. Belmont 2017-12-14 19:09:48 -05:00 committed by GitHub
commit 0971e20baf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 416 additions and 296 deletions

View File

@ -137,6 +137,7 @@ debugger_commands::debugger_commands(running_machine& machine, debugger_cpu& cpu
/* add all the commands */
m_console.register_command("help", CMDFLAG_NONE, 0, 0, 1, std::bind(&debugger_commands::execute_help, this, _1, _2));
m_console.register_command("html", CMDFLAG_NONE, 0, 0, 0, std::bind(&debugger_commands::execute_html, this, _1, _2));
m_console.register_command("print", CMDFLAG_NONE, 0, 1, MAX_COMMAND_PARAMS, std::bind(&debugger_commands::execute_print, this, _1, _2));
m_console.register_command("printf", CMDFLAG_NONE, 0, 1, MAX_COMMAND_PARAMS, std::bind(&debugger_commands::execute_printf, this, _1, _2));
m_console.register_command("logerror", CMDFLAG_NONE, 0, 1, MAX_COMMAND_PARAMS, std::bind(&debugger_commands::execute_logerror, this, _1, _2));
@ -553,6 +554,19 @@ void debugger_commands::execute_help(int ref, const std::vector<std::string> &pa
}
/*-------------------------------------------------
execute_html - generate debughelp.html
-------------------------------------------------*/
void debugger_commands::execute_html(int ref, const std::vector<std::string> &params)
{
if (debug_generate_html())
m_console.printf("debughelp.html has been successfully created.\n");
else
m_console.printf("Error creating debughelp.html.");
}
/*-------------------------------------------------
execute_print - execute the print command
-------------------------------------------------*/

View File

@ -93,6 +93,7 @@ private:
void execute_trace_internal(int ref, const std::vector<std::string> &params, bool trace_over);
void execute_help(int ref, const std::vector<std::string> &params);
void execute_html(int ref, const std::vector<std::string> &params);
void execute_print(int ref, const std::vector<std::string> &params);
void execute_printf(int ref, const std::vector<std::string> &params);
void execute_logerror(int ref, const std::vector<std::string> &params);

View File

@ -21,6 +21,8 @@
#define CONSOLE_HISTORY (10000)
#define CONSOLE_LINE_CHARS (100)
static const std::string html_preopen = "<pre>";
static const std::string html_preclose = "</pre>";
/***************************************************************************
@ -35,16 +37,29 @@ struct help_item
/***************************************************************************
MACROS
***************************************************************************/
#define HTML_TRY(f) do { if (f < 0) return false; } while (0)
/***************************************************************************
LOCAL VARIABLES
***************************************************************************/
std::string debug_buffer;
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
void debug_format_chapter_html(int index);
/***************************************************************************
@ -78,6 +93,7 @@ static const help_item static_help_list[] =
"Type help <command> for further details on each command\n"
"\n"
" help [<topic>] -- get help on a particular topic\n"
" html -- print all debugger help to an html file\n"
" do <expression> -- evaluates the given expression\n"
" symlist [<cpu>] -- lists registered symbols\n"
" softreset -- executes a soft reset\n"
@ -94,7 +110,7 @@ static const help_item static_help_list[] =
" pcatmemd <address>[,<cpu>] -- query which PC wrote to a given data memory address for the current CPU\n"
" pcatmemi <address>[,<cpu>] -- query which PC wrote to a given I/O memory address for the current CPU\n"
" (Note: you can also query this info by right clicking in a memory window\n"
" rewind[rw] -- go back in time by loading the most recent rewind state"
" rewind[rw] -- go back in time by loading the most recent rewind state\n"
" statesave[ss] <filename> -- save a state file for the current driver\n"
" stateload[sl] <filename> -- load a state file for the current driver\n"
" snap [<filename>] -- save a screen snapshot.\n"
@ -1389,43 +1405,43 @@ static const help_item static_help_list[] =
"The cheatnext command will make comparisons with the last search matches.\n"
"Possible <condition>:\n"
" all\n"
" no <comparisonvalue> needed.\n"
" use to update the last value without changing the current matches.\n"
"No <comparisonvalue> needed.\n"
"Use to update the last value without changing the current matches.\n"
" equal [eq]\n"
" without <comparisonvalue> search for all bytes that are equal to the last search.\n"
" with <comparisonvalue> search for all bytes that are equal to the <comparisonvalue>.\n"
"Without <comparisonvalue> search for all bytes that are equal to the last search.\n"
"With <comparisonvalue> search for all bytes that are equal to the <comparisonvalue>.\n"
" notequal [ne]\n"
" without <comparisonvalue> search for all bytes that are not equal to the last search.\n"
" with <comparisonvalue> search for all bytes that are not equal to the <comparisonvalue>.\n"
"Without <comparisonvalue> search for all bytes that are not equal to the last search.\n"
"With <comparisonvalue> search for all bytes that are not equal to the <comparisonvalue>.\n"
" decrease [de, +]\n"
" without <comparisonvalue> search for all bytes that have decreased since the last search.\n"
" with <comparisonvalue> search for all bytes that have decreased by the <comparisonvalue> since the last search.\n"
"Without <comparisonvalue> search for all bytes that have decreased since the last search.\n"
"With <comparisonvalue> search for all bytes that have decreased by the <comparisonvalue> since the last search.\n"
" increase [in, -]\n"
" without <comparisonvalue> search for all bytes that have increased since the last search.\n"
" with <comparisonvalue> search for all bytes that have increased by the <comparisonvalue> since the last search.\n"
"Without <comparisonvalue> search for all bytes that have increased since the last search.\n"
"With <comparisonvalue> search for all bytes that have increased by the <comparisonvalue> since the last search.\n"
" decreaseorequal [deeq]\n"
" no <comparisonvalue> needed.\n"
" search for all bytes that have decreased or have same value since the last search.\n"
"No <comparisonvalue> needed.\n"
"Search for all bytes that have decreased or have same value since the last search.\n"
" increaseorequal [ineq]\n"
" no <comparisonvalue> needed.\n"
" search for all bytes that have decreased or have same value since the last search.\n"
"No <comparisonvalue> needed.\n"
"Search for all bytes that have decreased or have same value since the last search.\n"
" smallerof [lt]\n"
" without <comparisonvalue> this condition is invalid\n"
" with <comparisonvalue> search for all bytes that are smaller than the <comparisonvalue>.\n"
"Without <comparisonvalue> this condition is invalid\n"
"With <comparisonvalue> search for all bytes that are smaller than the <comparisonvalue>.\n"
" greaterof [gt]\n"
" without <comparisonvalue> this condition is invalid\n"
" with <comparisonvalue> search for all bytes that are larger than the <comparisonvalue>.\n"
"Without <comparisonvalue> this condition is invalid\n"
"With <comparisonvalue> search for all bytes that are larger than the <comparisonvalue>.\n"
" changedby [ch, ~]\n"
" without <comparisonvalue> this condition is invalid\n"
" with <comparisonvalue> search for all bytes that have changed by the <comparisonvalue> since the last search.\n"
"Without <comparisonvalue> this condition is invalid\n"
"With <comparisonvalue> search for all bytes that have changed by the <comparisonvalue> since the last search.\n"
"\n"
"Examples:\n"
"\n"
" cheatnext increase\n"
" search for all bytes that have increased since the last search.\n"
"Search for all bytes that have increased since the last search.\n"
"\n"
" cheatnext decrease, 1\n"
" search for all bytes that have decreased by 1 since the last search.\n"
"Search for all bytes that have decreased by 1 since the last search.\n"
},
{
"cheatnextf",
@ -1435,43 +1451,43 @@ static const help_item static_help_list[] =
"The cheatnextf command will make comparisons with the initial search.\n"
"Possible <condition>:\n"
" all\n"
" no <comparisonvalue> needed.\n"
" use to update the last value without changing the current matches.\n"
"No <comparisonvalue> needed.\n"
"Use to update the last value without changing the current matches.\n"
" equal [eq]\n"
" without <comparisonvalue> search for all bytes that are equal to the initial search.\n"
" with <comparisonvalue> search for all bytes that are equal to the <comparisonvalue>.\n"
"Without <comparisonvalue> search for all bytes that are equal to the initial search.\n"
"With <comparisonvalue> search for all bytes that are equal to the <comparisonvalue>.\n"
" notequal [ne]\n"
" without <comparisonvalue> search for all bytes that are not equal to the initial search.\n"
" with <comparisonvalue> search for all bytes that are not equal to the <comparisonvalue>.\n"
"Without <comparisonvalue> search for all bytes that are not equal to the initial search.\n"
"With <comparisonvalue> search for all bytes that are not equal to the <comparisonvalue>.\n"
" decrease [de, +]\n"
" without <comparisonvalue> search for all bytes that have decreased since the initial search.\n"
" with <comparisonvalue> search for all bytes that have decreased by the <comparisonvalue> since the initial search.\n"
"Without <comparisonvalue> search for all bytes that have decreased since the initial search.\n"
"With <comparisonvalue> search for all bytes that have decreased by the <comparisonvalue> since the initial search.\n"
" increase [in, -]\n"
" without <comparisonvalue> search for all bytes that have increased since the initial search.\n"
" with <comparisonvalue> search for all bytes that have increased by the <comparisonvalue> since the initial search.\n"
"Without <comparisonvalue> search for all bytes that have increased since the initial search.\n"
"With <comparisonvalue> search for all bytes that have increased by the <comparisonvalue> since the initial search.\n"
" decreaseorequal [deeq]\n"
" no <comparisonvalue> needed.\n"
" search for all bytes that have decreased or have same value since the initial search.\n"
"No <comparisonvalue> needed.\n"
"Search for all bytes that have decreased or have same value since the initial search.\n"
" increaseorequal [ineq]\n"
" no <comparisonvalue> needed.\n"
" search for all bytes that have decreased or have same value since the initial search.\n"
"No <comparisonvalue> needed.\n"
"Search for all bytes that have decreased or have same value since the initial search.\n"
" smallerof [lt]\n"
" without <comparisonvalue> this condition is invalid.\n"
" with <comparisonvalue> search for all bytes that are smaller than the <comparisonvalue>.\n"
"Without <comparisonvalue> this condition is invalid.\n"
"With <comparisonvalue> search for all bytes that are smaller than the <comparisonvalue>.\n"
" greaterof [gt]\n"
" without <comparisonvalue> this condition is invalid.\n"
" with <comparisonvalue> search for all bytes that are larger than the <comparisonvalue>.\n"
"Without <comparisonvalue> this condition is invalid.\n"
"With <comparisonvalue> search for all bytes that are larger than the <comparisonvalue>.\n"
" changedby [ch, ~]\n"
" without <comparisonvalue> this condition is invalid\n"
" with <comparisonvalue> search for all bytes that have changed by the <comparisonvalue> since the initial search.\n"
"Without <comparisonvalue> this condition is invalid\n"
"With <comparisonvalue> search for all bytes that have changed by the <comparisonvalue> since the initial search.\n"
"\n"
"Examples:\n"
"\n"
" cheatnextf increase\n"
" search for all bytes that have increased since the initial search.\n"
"Search for all bytes that have increased since the initial search.\n"
"\n"
" cheatnextf decrease, 1\n"
" search for all bytes that have decreased by 1 since the initial search.\n"
"Search for all bytes that have decreased by 1 since the initial search.\n"
},
{
"cheatlist",
@ -1586,3 +1602,91 @@ const char *debug_get_help(const char *tag)
msglen += sprintf(&ambig_message[msglen], " help %s?\n", static_help_list[i].tag);
return ambig_message;
}
void debug_format_chapter_html(int index)
{
/* fetch the string */
debug_buffer = static_help_list[index].help;
/* substitute what html can't ignore */
strreplace(debug_buffer, "<", "&lt;");
/* iterate through all lines */
for (size_t linebreak = 0; ; )
{
/* find line break */
linebreak = debug_buffer.find_first_of('\n', linebreak);
/* check validity and advance */
if (linebreak >= debug_buffer.length() || linebreak++ == std::string::npos)
break;
/* check if the new line starts with a space */
if (debug_buffer[linebreak] != ' ')
{
/* close the tag and advance */
debug_buffer.insert(linebreak, html_preclose);
linebreak += html_preclose.length();
/* find the end of the line */
linebreak = debug_buffer.find_first_of('\n', linebreak);
/* check validity again */
if (linebreak >= debug_buffer.length() || linebreak == std::string::npos)
break;
/* open a new tag at the line end and advance */
debug_buffer.insert(linebreak, html_preopen);
linebreak += html_preopen.length();
}
}
}
bool debug_generate_html()
{
std::set<std::string> tags;
/* open the file */
FILE *file = fopen("debughelp.html", "w");
/* verify it */
if (!file)
return false;
/* print the help header */
debug_format_chapter_html(0);
HTML_TRY(fprintf(file, "<a name=\"Top\"></a>%s%s<br>", debug_buffer.c_str(), html_preopen.c_str()));
/* close the tag opened in the header */
HTML_TRY(fprintf(file, "%s", html_preclose.c_str()));
/* sort the tags */
for (int i = 1; i < ARRAY_LENGTH(static_help_list); i++)
{
tags.insert(static_help_list[i].tag);
}
/* print the links to all chapters */
for (auto &tag : tags)
{
HTML_TRY(fprintf(file, "<a href=\"#%s\">%s</a><br>\n", tag.c_str(), tag.c_str()));
}
/* empty line */
HTML_TRY(fprintf(file, "<br>"));
/* format chapter contents */
for (int i = 1; i < ARRAY_LENGTH(static_help_list); i++)
{
/* link to the top, anchorize the chapter header, print the contents */
debug_format_chapter_html(i);
HTML_TRY(fprintf(file, "<a href=\"#Top\">Up</a> <a name=\"%s\"><h3>%s</h3></a>%s%s<br>",
static_help_list[i].tag, static_help_list[i].tag, html_preopen.c_str(), debug_buffer.c_str()));
}
/* close the html tag and the file */
HTML_TRY(fprintf(file, "%s", html_preclose.c_str()));
if (fclose(file))
return false;
return true;
}

View File

@ -20,5 +20,6 @@
/* help management */
const char * debug_get_help(const char *tag);
bool debug_generate_html();
#endif // MAME_EMU_DEBUG_DEBUGHLP_H