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

add more magic breakpoints fix #55 #56

Closed
wants to merge 0 commits into from
Closed

add more magic breakpoints fix #55 #56

wants to merge 0 commits into from

Conversation

therealdreg
Copy link
Member

@therealdreg therealdreg commented Jul 24, 2023

This PR was moved to #58

Implemented support for various types of magic breakpoints, along with the ability to modify them at runtime from within the debugger. So, the Windows XP NTLDR will no longer be a problem.

fix #55

windows xp ntldr have code like this:

0000000000020252: (                    ): mov cr0, eax              ; 0f22c0
0000000000020255: (                    ): xchg bx, bx               ; 87db
0000000000020257: (                    ): nop                       ; 90

And this code is called a lot of times!

ring3 code CANT execute OUT instruction (0x8AE0)

So the ring3-dev cant use magic breakpoints on Bochs debugger (on first instance)

with this PR, the user can select what register should breaks:

#=======================================================================
# MAGIC_BREAK:
# This enables the "magic breakpoint" feature when using the debugger.
# The useless cpu instructions XCHG %REGW, %REGW causes Bochs to enter the
# debugger mode. This might be useful for software development.
#
# %cx %dx %bx %sp %bp %si %di
#
# Example for breaking on "XCHGW %DI, %DI" or "CHGW %SP, %SP" execution
#   magic_break: enabled=1 %di %sp
#
# Example for breaking on "XCHG %BX, %BX" execution (Windows XP ntldr can cause problems with %BX)
#   magic_break: enabled=1
#=======================================================================
magic_break: enabled=1 %di %sp

This PR is 100% backward compatibility

Added a new command to change from debugger the mask of registers, example adding XCHGW %DI, %DI or XCHGW %BX, %BX

setmagicbps "%di %bx"

@stlintel @vruppert do you like it?

@therealdreg therealdreg changed the title add more magic breakpoint types fix #55 add more magic breakpoints fix #55 Jul 24, 2023
bochs/.bochsrc Outdated
# debugger mode. This might be useful for software development.
#
# Example:
# Register number id:
# 0: DISABLE MAGIC_BREAK
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I haven't even notice these pull requests.
For some reason I didn't receive a notification from github,
This one is fine (with small adjustments to make to match general Bochs coding style).
How about adding capability to control/toggle them from inside the debugger interface ?
How about enabling more than one together ?
I think it should be a bitmask of 8 bits instead of bool in bx_dbg.magic_break and checking smth like
((1<dst()) & bx_dbg.magic_break)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome idea! I will do it :-)

@therealdreg
Copy link
Member Author

therealdreg commented Aug 19, 2023

Done, @stlintel take a look

multiple_magic_bps

This PR is 100% backward compatibility,

btw @stlintel who upload the new parser and lexer files? me or you?

bochs/.bochsrc Outdated Show resolved Hide resolved
bochs/bx_debug/dbg_main.cc Outdated Show resolved Hide resolved
bochs/bx_debug/dbg_main.cc Outdated Show resolved Hide resolved
{
new_mask |= 1 << 1;
}
if (strstr(str, "%sp") != NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you think strstr is better than strcmp ?
in your case %spd will be catched too as well as %sp

bochs/bx_debug/parser.y Outdated Show resolved Hide resolved
bochs/cpu/data_xfer16.cc Outdated Show resolved Hide resolved
bochs/doc/docbook/user/user.dbk Outdated Show resolved Hide resolved
bochs/doc/docbook/user/user.dbk Outdated Show resolved Hide resolved
@therealdreg
Copy link
Member Author

@stlintel take a look! more suggestions?

bochs/bx_debug/dbg_main.cc Outdated Show resolved Hide resolved
{
new_mask |= 1 << MBP_CX;
}
if (strstr(str, "dx") != NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still - why strstr ?

bochs/bx_debug/dbg_main.cc Outdated Show resolved Hide resolved
bochs/bx_debug/debug.h Outdated Show resolved Hide resolved
@@ -3791,7 +3840,7 @@ void bx_dbg_print_help(void)
dbg_printf("h|help command - show short command description\n");
dbg_printf("-*- Debugger control -*-\n");
dbg_printf(" help, q|quit|exit, set, instrument, show, trace, trace-reg,\n");
dbg_printf(" trace-mem, u|disasm, ldsym, slist, addlyt, remlyt, lyt, source\n");
dbg_printf(" trace-mem, u|disasm, ldsym, setmagicbps, slist, addlyt, remlyt, lyt, source\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about clearmagicbps ?

bochs/config.cc Outdated Show resolved Hide resolved
bochs/cpu/data_xfer16.cc Outdated Show resolved Hide resolved
@stlintel
Copy link
Contributor

stlintel commented Aug 20, 2023

di is the 7 register id, so I store it in 7nth position in mask
for a xchg di, di --> src() = 7
I need check the 7-nth bit in mask: 1 X X X X X X
to generate 1000000b I need do: 1 << 6

Bits are counted from 0:
#define AX 0 mask = 1
#define CX 1 mask = 2
#define DX 2 mask = 4
#define BX 3 mask = 8
#define SP 4 mask = 0x10 or mask = (1<<regnum)
#define BP 5 mask = 0x20
#define SI 6 mask = 0x40
#define DI 7 mask = 0x80

why -1 ?
AX will be never in use

BTW, to generate 1000000 you need 1<<7

@stlintel
Copy link
Contributor

Please also pay attention on indentation requirements

@therealdreg
Copy link
Member Author

therealdreg commented Aug 20, 2023

@stlintel I fix my coding style and I remove -1 and checking 0. do you like in this way?

Tested and working 100%

image

bochs/bx_debug/debug.h Outdated Show resolved Hide resolved
bochs/bx_debug/debug.h Outdated Show resolved Hide resolved
bochs/bx_debug/dbg_main.cc Outdated Show resolved Hide resolved
bochs/doc/docbook/user/user.dbk Outdated Show resolved Hide resolved
@therealdreg
Copy link
Member Author

done! @stlintel

image

{
dbg_printf("magic breakpoint mask: 0x%x ", mask);

if (mask & MBP_CX) {
Copy link
Contributor

@stlintel stlintel Aug 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static const char *regs = { "ax" /* not accessible */, "cx", "dx", "bx", "sp", "bp", "si", "di" };
for (int i=1;i<8;i++)
  if (mask & (1<<i))
    dbg_printf("%s ", regs[i]);


Bit8u bx_dbg_get_magic_bp_mask_from_str(const char *str)
{
Bit8u new_mask = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

for (int i=1; i<8;i++)
  if (strstr(str, regs[i])
    new_mask |= (1<<i)

// bx for backward compatilibility
if (new_mask == 0)
  new_mask  = (1<<BX_16BIT_REG_BX);

@@ -204,6 +208,16 @@ int bx_dbg_lbreakpoint_symbol_command(const char *Symbol, const char *condition)
bx_address bx_dbg_get_symbol_value(const char *Symbol);
const char* bx_dbg_disasm_symbolic_address(bx_address eip, bx_address base);

typedef enum {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and without that enum

@therealdreg
Copy link
Member Author

therealdreg commented Aug 20, 2023

@stlintel I'm closing this PR because it has become a mess; let's continue in #58

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

Successfully merging this pull request may close these issues.

magic breakpoints problem on XP ntldr
2 participants