Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Breakpoints & Scripting support for Debugger #198

Open
GoogleCodeExporter opened this issue Sep 16, 2015 · 4 comments
Open

Conditional Breakpoints & Scripting support for Debugger #198

GoogleCodeExporter opened this issue Sep 16, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

Conditional breakpoints require some form of parser for processing
expressions, and if any parser is going to be included, there should be
some thought given to trapping or logging debugging messages 'printed' by
an emulated rom.

A tracepoint for instance should be able to accomplish something similar to
the trick used below for printing debug messages generated by Zelda OOT.


Following is a function written by ZZT32 for extracting debugging messages
from N64 roms.  It needs to be run when zelda jumps to address: 0x80002130

   1.      #include <stdio.h>
   2.      #include <stdint.h>
   3.      #include "../r4300/r4300.h"
   4.      #include "../memory/memory.h"
   5.       
   6.      #define SWAP_WORD(x)            \
   7.      (                               \
   8.          ((x) & 0xFF000000) >> 24 |  \
   9.          ((x) & 0x00FF0000) >> 8  |  \
  10.          ((x) & 0x0000FF00) << 8  |  \
  11.          ((x) & 0x000000FF) << 24    \
  12.      )
  13.       
  14.      static void swap_mem ( void * src, int size )
  15.      {
  16.          int i, w;
  17.         
  18.          for( i = 0; i < size; i += 4, src +=4 )
  19.              *(int*)src = SWAP_WORD(*(int*)src);
  20.     }
  21.       
  22.      /*
  23.      ** Get a string from the N64's memory
  24.      */
  25.      char * getn64string ( uint32_t addr )
  26.      {
  27.          char * str;
  28.          char * ostr;
  29.          char * fstr;
  30.          uint32_t word;
  31.          int len = 0;
  32.          int strsize;
  33.          int ptr = (addr & 0x00FFFFFF) / 4;
  34.          int optr = ptr;
  35.          int i;
  36.         
  37.          if( !addr )
  38.              return NULL;
  39.         
  40.          /* Read 512 bytes */
  41.          ostr = str = malloc( 512 );
  42.          memcpy( str, &rdram[ptr], 512 );
  43.          swap_mem( str, 512 );
  44.         
  45.          if( addr % 4 )
  46.              str += addr % 4;
  47.         
  48.          fstr = strdup(str);
  49.          free( ostr );
  50.         
  51.          return fstr;
  52.      }
  53.       
  54.      /*
  55.      ** Get an argument
  56.      */
  57.      unsigned getn64arg ( int id )
  58.      {
  59.          if( id < 4 )
  60.              return reg[4 + id];
  61.         
  62.          /* Pull it off the stack */
  63.          return rdram[(reg[29]&0x00FFFFFF)/4 + id];
  64.      }
  65.       
  66.      /*
  67.      ** The following function will sprint a string to a local
variable that was
  68.      ** actually supposed to be done on the N64.
  69.      **
  70.      ** start_reg is the argument register the FMT is (counting from 0)
  71.      */
  72.      int n64sprintf ( char * dest, int start_reg )
  73.      {
  74.          char * ptr;
  75.          char * fmt;
  76.          char buff[2048], buff2[2048];
  77.          int s = 0, d = 0;
  78.          int i;
  79.          int argid = 1;
  80.         
  81.          /* Get the format string */
  82.          fmt = getn64string( (unsigned)reg[start_reg] );
  83.         
  84.          /* Step through it */
  85.          for( s = 0; fmt[s]; s++ )
  86.          {
  87.              /* No format string? */
  88.              if( fmt[s] != '%' )
  89.                  goto straight_copy;
  90.             
  91.              /* We has a format string */
  92.              for( i = 0; fmt[s + i] && !isspace(fmt[s + i]); i++ )
  93.              {
  94.                  buff[i] = fmt[s + i];
  95.                  if( fmt[s+i+1] == '%' )
  96.                      break;
  97.              }
  98.              buff[i] = '\0';
  99.              s += i - 1;
 100.             
 101.              /* Is this a string? */
 102.              if( strstr(buff, "%s") )
 103.              {
 104.                  char * str = getn64string(getn64arg(argid));
 105.                  sprintf( buff2, buff, str );
 106.                  free( str );
 107.              }
 108.              else
 109.              {
 110.                  sprintf( buff2, buff, getn64arg(argid) );
 111.              }
 112.             
 113.              argid++;
 114.             
 115.              /* Copy output to destination */
 116.              for( i = 0; buff2[i]; i++ )
 117.                  dest[d++] = buff2[i];
 118.             
 119.              /* Continue loop */
 120.              continue;
 121.             
 122.              /* Copy normally */
 123.          straight_copy:
 124.              dest[d++] = fmt[s];
 125.          }
 126.         
 127.          /* Terminate string */
 128.          free( fmt );
 129.          dest[d] = '\0';
 130.          return d;
 131.      }

Original issue reported on code.google.com by [email protected] on 13 Jan 2009 at 4:40

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 13 Jan 2009 at 4:42

  • Added labels: Component-Mupen64, Priority-Medium, Type-Enhancement

@GoogleCodeExporter
Copy link
Author

I'm not looking for anything fancy here. I'd just love to see the ability to do
read/write breakpoints. I'm a little tired of only being able to do that with 
Nemu.
Could someone please work on adding something? :(

Original comment by [email protected] on 15 Feb 2010 at 7:07

@GoogleCodeExporter
Copy link
Author

Actually the core already contains code to handle read/write breakpoints.  The 
only
problem is that we don't have an up-to-date GUI, and the console front-end 
doesn't
have a debugger.

Original comment by [email protected] on 15 Feb 2010 at 11:56

@GoogleCodeExporter
Copy link
Author

It looks like at some point the debugger enhancements I made a long time ago, 
such as the breakpoint window and variable list, got merged into the official 
build? Not sure when that happened, but it definitely lets you set breakpoints.

Scripting is an interesting idea. With the 2.0 plugin API one could write a 
plugin that exposes various debugging functions to Lua. I might just try that 
pretty soon.

Original comment by [email protected] on 14 May 2011 at 2:26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant