From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jiri Smid To: gdb-patches@sources.redhat.com Cc: Mark Kettenis , Eli Zaretskii Subject: Re: [RFA]: x86_64 target - multiarch Date: Tue, 11 Sep 2001 05:13:00 -0000 Message-id: References: X-SW-Source: 2001-09/msg00155.html Eli Zaretskii writes: > On 6 Sep 2001, Mark Kettenis wrote: > > > Eli already pointed out that the you should try to use the generic > > hardware watchpoint support in i386-nat.c instead of rolling your own > > here. > > I don't think x86_64 can use i386-nat.c's implementation, unless > i386-nat.c is extended to handle debug registers that can watch regions > wider than 4 bytes. One thing that definitely needs to be changed is the > size_try_array array, and some of the functions don't expect to see a > region more than 4 bytes long. > > But even if x86_64 does not use i386-nat.c, they could roll a similar > implementation, and thus support the same features. FWIW, NEWS > already promises that all x86 targets support those features ;-) Support for 8-byte wide watchpoints doesn't need too many changes in i386-nat.c. If this patch is be accepted the x86-64 target could use the generic i386 hardware watchpoint support. Index: gdb/ChangeLog from Jiri Smid * i386-nat.c (TARGET_HAS_DR_LEN_8, DR_LEN_8): Declare. (i386_length_and_rw_bits, i386_handle_nonaligned_watchpoint, i386_insert_watchpoint, i386_remove_watchpoint): Add support for 8-byte wide watchpoints. (i386_show_dr): Debug message format string change. Index: gdb/i386-nat.c =================================================================== RCS file: /cvs/src/src/gdb/i386-nat.c,v retrieving revision 1.3 diff -c -3 -p -r1.3 i386-nat.c *** i386-nat.c 2001/04/18 00:37:49 1.3 --- i386-nat.c 2001/09/11 11:59:18 *************** *** 60,65 **** --- 60,70 ---- #ifdef I386_USE_GENERIC_WATCHPOINTS + /* Support for 8-byte wide hw watchpoints. */ + #ifndef TARGET_HAS_DR_LEN_8 + #define TARGET_HAS_DR_LEN_8 0 + #endif + /* Debug registers' indices. */ #define DR_NADDR 4 /* the number of debug address registers */ #define DR_STATUS 6 /* index of debug status register (DR6) */ *************** *** 89,94 **** --- 94,100 ---- #define DR_LEN_1 (0x0 << 2) /* 1-byte region watch or breakpt */ #define DR_LEN_2 (0x1 << 2) /* 2-byte region watch */ #define DR_LEN_4 (0x3 << 2) /* 4-byte region watch */ + #define DR_LEN_8 (0x2 << 2) /* 8-byte region watch (x86-64) */ /* Local and Global Enable flags in DR7. *************** i386_show_dr (const char *func, CORE_ADD *** 252,260 **** dr_control_mirror, dr_status_mirror); ALL_DEBUG_REGISTERS(i) { ! printf_unfiltered ("\tDR%d: addr=%08lx, ref.count=%d DR%d: addr=%08lx, ref.count=%d\n", ! i, dr_mirror[i], dr_ref_count[i], ! i+1, dr_mirror[i+1], dr_ref_count[i+1]); i++; } } --- 258,266 ---- dr_control_mirror, dr_status_mirror); ALL_DEBUG_REGISTERS(i) { ! printf_unfiltered ("\tDR%d: addr=%p, ref.count=%d DR%d: addr=%p, ref.count=%d\n", ! i, (void *)dr_mirror[i], dr_ref_count[i], ! i+1, (void*)dr_mirror[i+1], dr_ref_count[i+1]); i++; } } *************** Invalid hw breakpoint type %d in i386_le *** 291,302 **** switch (len) { - case 4: - return (DR_LEN_4 | rw); - case 2: - return (DR_LEN_2 | rw); case 1: return (DR_LEN_1 | rw); default: internal_error (__FILE__, __LINE__, "\ Invalid hw breakpoint length %d in i386_length_and_rw_bits.\n", len); --- 297,311 ---- switch (len) { case 1: return (DR_LEN_1 | rw); + case 2: + return (DR_LEN_2 | rw); + case 4: + return (DR_LEN_4 | rw); + case 8: + if (TARGET_HAS_DR_LEN_8) + return (DR_LEN_8 | rw); default: internal_error (__FILE__, __LINE__, "\ Invalid hw breakpoint length %d in i386_length_and_rw_bits.\n", len); *************** i386_handle_nonaligned_watchpoint (i386_ *** 407,426 **** int align; int size; int rv = 0, status = 0; ! static int size_try_array[4][4] = { ! { 1, 1, 1, 1 }, /* trying size one */ ! { 2, 1, 2, 1 }, /* trying size two */ ! { 2, 1, 2, 1 }, /* trying size three */ ! { 4, 1, 2, 1 } /* trying size four */ }; while (len > 0) { ! align = addr % 4; ! /* Four is the maximum length an x86 debug register can watch. */ ! size = size_try_array[len > 4 ? 3 : len - 1][align]; if (what == WP_COUNT) /* size_try_array[] is defined so that each iteration through the loop is guaranteed to produce an address and a size --- 416,441 ---- int align; int size; int rv = 0, status = 0; + int max_wp_len = TARGET_HAS_DR_LEN_8 ? 8 : 4; ! static int size_try_array[8][8] = { ! {1, 1, 1, 1, 1, 1, 1, 1}, /* trying size one */ ! {2, 1, 2, 1, 2, 1, 2, 1}, /* trying size two */ ! {2, 1, 2, 1, 2, 1, 2, 1}, /* trying size three */ ! {4, 1, 2, 1, 4, 1, 2, 1}, /* trying size four */ ! {4, 1, 2, 1, 4, 1, 2, 1}, /* trying size five */ ! {4, 1, 2, 1, 4, 1, 2, 1}, /* trying size six */ ! {4, 1, 2, 1, 4, 1, 2, 1}, /* trying size seven */ ! {8, 1, 2, 1, 4, 1, 2, 1}, /* trying size eight */ }; while (len > 0) { ! align = addr % max_wp_len; ! /* Four(eigth on x86_64) is the maximum length an x86 debug register ! can watch. */ ! size = size_try_array[len > max_wp_len ? (max_wp_len - 1) : len - 1][align]; if (what == WP_COUNT) /* size_try_array[] is defined so that each iteration through the loop is guaranteed to produce an address and a size *************** i386_insert_watchpoint (CORE_ADDR addr, *** 466,472 **** { int retval; ! if (len == 3 || len > 4 || addr % len != 0) retval = i386_handle_nonaligned_watchpoint (WP_INSERT, addr, len, type); else { --- 481,488 ---- { int retval; ! if ((len != 1 && len !=2 && len !=4 && (TARGET_HAS_DR_LEN_8 && len !=8)) ! || addr % len != 0) retval = i386_handle_nonaligned_watchpoint (WP_INSERT, addr, len, type); else { *************** i386_remove_watchpoint (CORE_ADDR addr, *** 489,495 **** { int retval; ! if (len == 3 || len > 4 || addr % len != 0) retval = i386_handle_nonaligned_watchpoint (WP_REMOVE, addr, len, type); else { --- 505,512 ---- { int retval; ! if ((len != 1 && len !=2 && len !=4 && (TARGET_HAS_DR_LEN_8 && len !=8)) ! || addr % len != 0) retval = i386_handle_nonaligned_watchpoint (WP_REMOVE, addr, len, type); else { -- Jiri Smid --------------------------------------------------------------------- SuSE CR, s.r.o. e-mail: smid@suse.cz Drahobejlova 27 tel:+420 2 83095 373 190 00 Praha 9 fax:+420 2 83095 374 Ceska republika http://www.suse.cz