From nobody Fri Apr 12 09:37:41 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VGBLY4h1pz5H4Br; Fri, 12 Apr 2024 09:37:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VGBLY2f7lz4Dbs; Fri, 12 Apr 2024 09:37:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712914661; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z1VX8o7WlGsrxXFf2hDorSMROr2KvIpIDnNzf1W7QLk=; b=RnLD8eo3Co2r2A0XsVycfJU3Aq2sJh7xO+Mjcw3r4FerZAhFYIWQhjT7mcLIIOePz1EemW aRUV1NfJfLQxwoLmxzUqYTthrPgXPLHwpSu9EmZZ5drBnHU/iWITHbDQDK0LVr+cXAwoqh ZvljJuT+XTTOHg4vLiPwfOkjtILnBrOqmmD3EEsH3r8vWSc5oHvCk/f1r1ql+Jur3vKOYP UjdxFpFcZOj4y+TnkrI0QTGCVYomd64ThfjGuNNfUMgi2RH7tP8ni/b/9psDBqO3KsvLsn 4/NrjaEgzky7N1raAPSyTaxilTyOBSJxp9XrsqC+zbiG5TfztTZfqmCDzNMY5w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712914661; a=rsa-sha256; cv=none; b=YUuF8HxJqlVk8vjTCbt0TZTU70a3dEbVKbadst5cdH6RYXadL5ZePJ1RfTpjEUQ1OOcrtq lKJ+diZHYRbB+ceZnfH7cBex7oMrnzQZKII1TeLFYkhFv8ZthMEgVM0ipos9I1a8d4DtZM qPEoT3NxYqS+IsDMYRAXwV51B7dB5cIF6S2RtC7AmReuO79UNAwgWKk+xBsW3Hy8Kuyp+Y NNZMrBuswoFakDSSLDkS/1ckYsAD+rojsJxtdfk8IsHauyQwXo/viKQ6IwytMfmZ9CycWc RBOZcOIxnKIwrZeoeJmKcssN7F66qNnNs/n47OPkpQWInmaD+HnKRlXrFH6/Jg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712914661; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=z1VX8o7WlGsrxXFf2hDorSMROr2KvIpIDnNzf1W7QLk=; b=bdpnzplw2auApIH/i8yeJd+XF7sLD2ViUP3ZEUriztPt4e81t/8YYeZHPQbUUvbRYEru0o yP6t2GamBv9Lnh1b4I5Q+T0KwirN8CUTllYZw9QHVvH+xqORI6uVDGY7r9W89qnJs1MlK8 chDzL+vRwP0EC7JpqTUOwjTn0PCDVmQd6I4xkMDb0gdH/PsMi40ILp9481G5EMipQsTtxg SYErcRO0wNSokh/iivwEKjWTkYEXncAtydwz4E3rsfnYAXpZ3Sc+F6XbyaLrsKdjdNZKHz fTBJyr9mUimg3ekmFI75p048aA0q5a1uZTUcF2yblXEfPfasQxzfhAfiyFfCLQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VGBLY2FQjzky8; Fri, 12 Apr 2024 09:37:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43C9bf1s096619; Fri, 12 Apr 2024 09:37:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43C9bfiJ096616; Fri, 12 Apr 2024 09:37:41 GMT (envelope-from git) Date: Fri, 12 Apr 2024 09:37:41 GMT Message-Id: <202404120937.43C9bfiJ096616@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 076b64e83ac9 - main - sys/ddb: Add hardware breakpoint support to ddb List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 076b64e83ac9e0cfd361a58d5967dfa939fe8139 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=076b64e83ac9e0cfd361a58d5967dfa939fe8139 commit 076b64e83ac9e0cfd361a58d5967dfa939fe8139 Author: Andrew Turner AuthorDate: 2024-03-12 17:01:26 +0000 Commit: Andrew Turner CommitDate: 2024-04-12 09:32:41 +0000 sys/ddb: Add hardware breakpoint support to ddb As with hardware watchpoints add support for hardware breakpoints. The command is only enabled on architectures that report support for them. Currently no architectures do, however arm64 will add support in a future change. Reviewed by: jhb (earlier version) Sponsored by: Arm Ltd Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D22191 --- sys/ddb/db_break.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++----- sys/ddb/db_command.c | 4 +++ sys/ddb/ddb.h | 7 ++++ 3 files changed, 99 insertions(+), 8 deletions(-) diff --git a/sys/ddb/db_break.c b/sys/ddb/db_break.c index 65045d909890..44b51fb7f402 100644 --- a/sys/ddb/db_break.c +++ b/sys/ddb/db_break.c @@ -35,10 +35,14 @@ */ #include +#include +#include #include #include +#include + #include #include #include @@ -61,6 +65,17 @@ static struct db_breakpoint_type db_breakpoint = { .db_breakpoint_list = NULL, }; +#ifdef HAS_HW_BREAKPOINT +static struct db_breakpoint db_hbreak_table[NHBREAKPOINTS]; + +static struct db_breakpoint_type db_hbreakpoint = { + .db_next_free_breakpoint = &db_hbreak_table[0], + .db_breakpoint_limit = &db_hbreak_table[NHBREAKPOINTS], + .db_free_breakpoints = NULL, + .db_breakpoint_list = NULL, +}; +#endif + static db_breakpoint_t db_breakpoint_alloc( struct db_breakpoint_type *bkpt_type); static void db_breakpoint_free(struct db_breakpoint_type *bkpt_typ, @@ -70,7 +85,7 @@ static void db_delete_breakpoint(struct db_breakpoint_type *bkpt_type, static db_breakpoint_t db_find_breakpoint(struct db_breakpoint_type *bkpt_type, vm_map_t map, db_addr_t addr); static void db_list_breakpoints(void); -static void db_set_breakpoint(struct db_breakpoint_type *bkpt_type, +static bool db_set_breakpoint(struct db_breakpoint_type *bkpt_type, vm_map_t map, db_addr_t addr, int count); static db_breakpoint_t @@ -100,7 +115,7 @@ db_breakpoint_free(struct db_breakpoint_type *bkpt_type, db_breakpoint_t bkpt) bkpt_type->db_free_breakpoints = bkpt; } -static void +static bool db_set_breakpoint(struct db_breakpoint_type *bkpt_type, vm_map_t map, db_addr_t addr, int count) { @@ -108,13 +123,13 @@ db_set_breakpoint(struct db_breakpoint_type *bkpt_type, vm_map_t map, if (db_find_breakpoint(bkpt_type, map, addr)) { db_printf("Already set.\n"); - return; + return (false); } bkpt = db_breakpoint_alloc(bkpt_type); if (bkpt == 0) { db_printf("Too many breakpoints.\n"); - return; + return (false); } bkpt->map = map; @@ -125,6 +140,8 @@ db_set_breakpoint(struct db_breakpoint_type *bkpt_type, vm_map_t map, bkpt->link = bkpt_type->db_breakpoint_list; bkpt_type->db_breakpoint_list = bkpt; + + return (true); } static void @@ -171,7 +188,16 @@ db_find_breakpoint(struct db_breakpoint_type *bkpt_type, vm_map_t map, db_breakpoint_t db_find_breakpoint_here(db_addr_t addr) { - return db_find_breakpoint(&db_breakpoint, db_map_addr(addr), addr); + db_breakpoint_t bkpt; + + bkpt = db_find_breakpoint(&db_breakpoint, db_map_addr(addr), addr); +#ifdef HAS_HW_BREAKPOINT + if (bkpt == NULL) + bkpt = db_find_breakpoint(&db_hbreakpoint, db_map_addr(addr), + addr); +#endif + + return (bkpt); } static bool db_breakpoints_inserted = true; @@ -189,6 +215,9 @@ do { \ db_put_value(addr, BKPT_SIZE, *storage) #endif +/* + * Set software breakpoints. + */ void db_set_breakpoints(void) { @@ -205,6 +234,9 @@ db_set_breakpoints(void) } } +/* + * Clean software breakpoints. + */ void db_clear_breakpoints(void) { @@ -222,7 +254,7 @@ db_clear_breakpoints(void) } /* - * List breakpoints. + * List software breakpoints. */ static void db_list_breakpoints(void) @@ -246,7 +278,9 @@ db_list_breakpoints(void) } } -/* Delete breakpoint */ +/* + * Delete software breakpoint + */ /*ARGSUSED*/ void db_delete_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif) @@ -255,7 +289,9 @@ db_delete_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif) (db_addr_t)addr); } -/* Set breakpoint with skip count */ +/* + * Set software breakpoint with skip count + */ /*ARGSUSED*/ void db_breakpoint_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif) @@ -267,11 +303,55 @@ db_breakpoint_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif) count); } +#ifdef HAS_HW_BREAKPOINT +/* + * Delete hardware breakpoint + */ +void +db_deletehbreak_cmd(db_expr_t addr, bool have_addr, db_expr_t count, + char *modif) +{ + if (count == -1) + count = 1; + + if (kdb_cpu_clr_breakpoint(addr) != 0) { + db_printf("hardware breakpoint could not be delete\n"); + return; + } + + db_delete_breakpoint(&db_hbreakpoint, db_map_addr(addr), + (db_addr_t)addr); +} + +/* + * Set hardware breakpoint + */ +void +db_hbreakpoint_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif) +{ + if (count == -1) + count = 1; + + if (!db_set_breakpoint(&db_hbreakpoint, db_map_addr(addr), + (db_addr_t)addr, count)) + return; + + if (kdb_cpu_set_breakpoint(addr) != 0) { + db_printf("hardware breakpoint could not be set\n"); + db_delete_breakpoint(&db_hbreakpoint, db_map_addr(addr), + (db_addr_t)addr); + } +} +#endif + /* list breakpoints */ void db_listbreak_cmd(db_expr_t dummy1, bool dummy2, db_expr_t dummy3, char *dummy4) { db_list_breakpoints(); +#ifdef HAS_HW_BREAKPOINT + db_md_list_breakpoints(); +#endif } /* diff --git a/sys/ddb/db_command.c b/sys/ddb/db_command.c index 0c88d496f6b8..f621bd614ca2 100644 --- a/sys/ddb/db_command.c +++ b/sys/ddb/db_command.c @@ -126,6 +126,10 @@ static struct db_command db_cmds[] = { DB_CMD("delete", db_delete_cmd, 0), DB_CMD("d", db_delete_cmd, 0), DB_CMD("dump", db_dump, DB_CMD_MEMSAFE), +#ifdef HAS_HW_BREAKPOINT + DB_CMD("dhbreak", db_deletehbreak_cmd, 0), + DB_CMD("hbreak", db_hbreakpoint_cmd, 0), +#endif DB_CMD("break", db_breakpoint_cmd, 0), DB_CMD("b", db_breakpoint_cmd, 0), DB_CMD("dwatch", db_deletewatch_cmd, 0), diff --git a/sys/ddb/ddb.h b/sys/ddb/ddb.h index bb92fef63e94..ab7dab1daa45 100644 --- a/sys/ddb/ddb.h +++ b/sys/ddb/ddb.h @@ -299,6 +299,13 @@ db_cmdfcn_t db_watchpoint_cmd; db_cmdfcn_t db_write_cmd; db_cmdfcn_t db_pprint_cmd; +#ifdef HAS_HW_BREAKPOINT +void db_md_list_breakpoints(void); + +db_cmdfcn_t db_deletehbreak_cmd; +db_cmdfcn_t db_hbreakpoint_cmd; +#endif + /* * Interface between DDB and the DDB output capture facility. */