From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33111 invoked by alias); 25 Jul 2017 15:16:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 30732 invoked by uid 89); 25 Jul 2017 15:15:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=ling, ADI, adi, ISM X-HELO: mail-it0-f44.google.com Received: from mail-it0-f44.google.com (HELO mail-it0-f44.google.com) (209.85.214.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Jul 2017 15:15:37 +0000 Received: by mail-it0-f44.google.com with SMTP id h199so52657332ith.0 for ; Tue, 25 Jul 2017 08:15:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=nTYcs/VS8ANXAx9kOXvEU3WhzWToB6zFSpgwep99NJ4=; b=gE9mYWb0wMWEr8RJqNXuW2D79Tiu4H7tPNnnQD8fo/Fb/go9EhRnoVvezM37L2L8fS XLAgUtdsT3x5dm1BoGadeTKpxraROYpmGiYFo028XIjwvLdfqb1WZIs52C+fYb2rjDgJ kdYiYhH2TnhkumBtyeMXkHiFrTsiCnjvcr8XnGgeBrSTza1Wv0M7/Fu2s8VpVlh70lse iqVYwt4+X8YCn3w6xB0weRqNxZsBn+jxd4AUUWe8Ech8BvNRYMxb7OC/sO2oZfrIm4kF rDneMHM4duvXk2ZjHrjAcpCebJ/cvP9o0wLIlF7Vg7gUEY554xfGaNQOp3jLgaS83ig9 0pzQ== X-Gm-Message-State: AIVw110YuVwZcUohSHXBb4YZzQ1QciAuXWb+u1LVZfB8/G/+gvszIEg+ cdTWoi30dfE+jCeu X-Received: by 10.36.77.136 with SMTP id l130mr819879itb.67.1500995726735; Tue, 25 Jul 2017 08:15:26 -0700 (PDT) Received: from E107787-LIN (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id z11sm6942309ioe.10.2017.07.25.08.15.25 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 25 Jul 2017 08:15:26 -0700 (PDT) From: Yao Qi To: Weimin Pan Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v4] gdb: ADI support References: <1500424890-112103-1-git-send-email-weimin.pan@oracle.com> Date: Tue, 25 Jul 2017 15:16:00 -0000 In-Reply-To: <1500424890-112103-1-git-send-email-weimin.pan@oracle.com> (Weimin Pan's message of "Tue, 18 Jul 2017 19:41:30 -0500") Message-ID: <86o9s8pmyg.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-07/txt/msg00366.txt.bz2 Weimin Pan writes: > +/* Per-process ADI stat info. */ > + > +struct sparc64_adi_info > +{ > + /* The process identifier. */ > + pid_t pid; > + > + /* The ADI stat. */ > + struct adi_stat_t stat; > + > + /* Linked list. */ > + struct sparc64_adi_info *next; > +}; Use C++ STL list. I suggested it on the v3 review. > + > +/* Normalize a versioned address - a VA with ADI bits (63-60) set. */ > + > +static CORE_ADDR > +adi_normalize_address (CORE_ADDR addr) > +{ > + struct adi_stat_t adi_stat =3D get_adi_info (ptid_get_pid (inferior_pt= id)); > + > + if (adi_stat.nbits) > + return ((CORE_ADDR)(((long)addr << adi_stat.nbits) >> adi_stat.nbits= )); > + return addr; > +} > + > +/* Align a normalized address - a VA with bit 59 sign extended into ADI = bits. */ This line is too long. > + > +static CORE_ADDR > +adi_align_address (CORE_ADDR naddr) > +{ > + struct adi_stat_t adi_stat =3D get_adi_info (ptid_get_pid (inferior_pt= id)); > + > + return (naddr - (naddr % adi_stat.blksize)) / adi_stat.blksize; > +} > + > + > +/* Read ADI version tag value for memory locations starting at "vaddr" > + for "size" number of bytes. */ > + > +static int > +adi_read_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags) > +{ > + int fd =3D adi_tag_fd (); > + if (fd =3D=3D -1) > + return -1; > + > + if (!adi_is_addr_mapped (vaddr, size)) > + { > + struct adi_stat_t adi_stat =3D get_adi_info (ptid_get_pid (inferio= r_ptid)); > + error(_("Address at 0x%lx is not in ADI maps"), vaddr*adi_stat.blk= size); These two lines are too long. > + } > + > + int target_errno; > + return target_fileio_pread (fd, tags, size, vaddr, &target_errno); > +} > + > +/* Write ADI version tag for memory locations starting at "vaddr" for > + "size" number of bytes to "tags". */ > + > +static int > +adi_write_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags) > +{ > + int fd =3D adi_tag_fd (); > + if (fd =3D=3D -1) > + return -1; > + > + if (!adi_is_addr_mapped (vaddr, size)) > + { > + struct adi_stat_t adi_stat =3D get_adi_info (ptid_get_pid (inferio= r_ptid)); > + error(_("Address at 0x%lx is not in ADI maps"), vaddr*adi_stat.blk= size); > + } > + > + int target_errno; > + return target_fileio_pwrite (fd, tags, size, vaddr, &target_errno); > +} > + > +/* Print ADI version tag value in "tags" for memory locations starting > + at "vaddr" with number of "cnt". */ > + Replace "tags" with TAGS, "cnt' with CNT, "vaddr" with VADDR. > +static void > +adi_print_versions (CORE_ADDR vaddr, size_t cnt, unsigned char *tags) > +{ > + int v_idx =3D 0; > + const int maxelts =3D 8; /* # of elements per line */ > + > + struct adi_stat_t adi_stat =3D get_adi_info (ptid_get_pid (inferior_pt= id)); > + > + while (cnt > 0) > + { > + QUIT; > + printf_filtered ("0x%016lx:\t", vaddr * adi_stat.blksize); > + for (int i =3D maxelts; i > 0 && cnt > 0; i--, cnt--) > + { > + if (tags[v_idx] =3D=3D 0xff) /* no version tag */ > + printf_filtered ("- "); > + else > + printf_filtered ("%1X ", tags[v_idx]); > + ++v_idx; > + } > + printf_filtered ("\n"); > + gdb_flush (gdb_stdout); > + vaddr +=3D maxelts; > + } > +} > + > + > +static void > +adi_assign_command (char *args, int from_tty) > +{ > + /* make sure program is active and adi is available */ > + if (!target_has_execution) > + error (_("ADI command requires a live process/thread")); > + > + if (!adi_available ()) > + error (_("No ADI information")); > + > + char *exp =3D args; > + if (exp =3D=3D 0) > + error_no_arg (_("Usage: adi assign|a[/count] =3D ")); > + > + char *q =3D (char *) strchr (exp, '=3D'); > + if (q) > + *q++ =3D 0; > + else > + error (_("Usage: adi assign|a[/count] =3D ")); > + > + size_t cnt =3D 1; > + char *p =3D args; > + if (exp && *exp =3D=3D '/') > + { > + p =3D exp + 1; > + cnt =3D get_number (&p); > + } > + > + CORE_ADDR next_address =3D 0; > + if (p !=3D 0 && *p !=3D 0) > + next_address =3D parse_and_eval_address (p); > + else > + error (_("Usage: adi assign|a[/count] =3D ")); > + > + int version =3D 0; > + if (q) /* parse version tag */ if (q !=3D NULL) > + { > + struct adi_stat_t adi_stat =3D get_adi_info (ptid_get_pid (inferio= r_ptid)); The ling is too long. > + version =3D parse_and_eval_long (q); > + if (version < 0 || version > adi_stat.max_version) > + error (_("Invalid ADI version tag %d"), version); > + } > + > + do_assign(next_address, cnt, version); > +} > + > +void > +_initialize_sparc64_adi_tdep (void) > +{ > + > + add_prefix_cmd ("adi", class_support, info_adi_command, > + _("ADI version related commands."), > + &sparc64adilist, "adi ", 0, &cmdlist); > + add_cmd ("examine", class_support, adi_examine_command, > + _("Examine ADI versions."), &sparc64adilist); > + add_alias_cmd ("x", "examine", no_class, 1, &sparc64adilist); > + add_cmd ("assign", class_support, adi_assign_command, > + _("Assign ADI versions."), &sparc64adilist); > + > +} > +=0C > + > /* The functions on this page are intended to be used to classify > function arguments. */ >=20=20 > @@ -1290,6 +1805,14 @@ sparc64_dwarf2_frame_init_reg (struct gdbarch *gdb= arch, int regnum, > } > } >=20=20 > +/* sparc64_addr_bits_remove - remove useless address bits */ > + > +static CORE_ADDR > +sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr) > +{ > + return adi_normalize_address (addr); > +} > + > void > sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) > { > @@ -1342,6 +1865,8 @@ sparc64_init_abi (struct gdbarch_info info, struct = gdbarch *gdbarch) >=20=20 > frame_unwind_append_unwinder (gdbarch, &sparc64_frame_unwind); > frame_base_set_default (gdbarch, &sparc64_frame_base); > + > + set_gdbarch_addr_bits_remove (gdbarch, sparc64_addr_bits_remove); > } > =0C >=20=20 > @@ -1666,3 +2191,4 @@ const struct sparc_fpregmap sparc64_bsd_fpregmap =3D > 0 * 8, /* %f0 */ > 32 * 8, /* %fsr */ > }; > +=0C > diff --git a/gdb/sparc64-tdep.h b/gdb/sparc64-tdep.h > index 324778e..da61a82 100644 > --- a/gdb/sparc64-tdep.h > +++ b/gdb/sparc64-tdep.h > @@ -138,4 +138,6 @@ extern struct trad_frame_saved_reg * >=20=20 > extern const struct sparc_fpregmap sparc64_bsd_fpregmap; >=20=20 > +extern void sparc64_forget_process (pid_t pid); > + > #endif /* sparc64-tdep.h */ > diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog > index 6b22498..5f8837f 100644 > --- a/gdb/testsuite/ChangeLog > +++ b/gdb/testsuite/ChangeLog > @@ -1,3 +1,7 @@ > +2017-07-18 Weimin Pan > + > + * gdb.arch/sparc64-adi.exp: New file. and gdb.arch/sparc64-adi.c. > + > 2017-07-09 Tom Tromey >=20=20 > * gdb.dwarf2/shortpiece.exp: New file. > diff --git a/gdb/testsuite/gdb.arch/sparc64-adi.c b/gdb/testsuite/gdb.arc= h/sparc64-adi.c > new file mode 100755 > index 0000000..a5557ef > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/sparc64-adi.c > @@ -0,0 +1,135 @@ > +/* Application Data Integrity (ADI) test in sparc64. > + > + Copyright 2017 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see .= */ > + > +#include "sparc64-adilib.h" > + > +#define MAPSIZE 8192 > +#define SHMSIZE 102400 > +#ifndef PROT_ADI > +#define PROT_ADI 0x10 > +#endif > + > +static int > +memory_fill(char *addr, size_t size, int pattern) > +{ In general, the test case should follow the GNU coding standard too. > + long *aligned_addr =3D (long *) addr; > + long i; > + for (i =3D 0; i < size / sizeof (long); i +=3D ONEKB) { > + *aligned_addr =3D pattern; > + aligned_addr =3D aligned_addr + ONEKB; > + } > + return (0); > +} > + > +int main() > +{ > + char *haddr; > + caddr_t vaddr; > + int version; > + > + // test ISM > + int shmid =3D shmget(IPC_PRIVATE, SHMSIZE, IPC_CREAT | 0666); > + if (shmid =3D=3D -1) { > + printf ("ERROR: shmget failed with an error:%d\n", errno); > + exit(1); The test case is run by GDB testsuite, rather than by human, so these printing isn't useful. > + } > + char *shmaddr =3D (char *)shmat(shmid, NULL, 0x666 | SHM_RND); > + if (shmaddr =3D=3D (char *)-1) { > + printf("ERROR: shmat failed with an error:%d\n", errno); > + shmctl(shmid, IPC_RMID, NULL); > + exit(1); > + } > + // enable ADI on ISM segment > + if (mprotect(shmaddr, SHMSIZE, PROT_READ|PROT_WRITE|PROT_ADI)) { > + perror("mprotect failed"); > + goto err_out; > + } > + if (memory_fill(shmaddr, SHMSIZE, 0xdeadbeaf) !=3D 0) { /* line breakpo= int here */ > + printf("ERROR: ISM cannot fill memory\n"); > + exit(1); > + } > + adi_clr_version(shmaddr, SHMSIZE); > + caddr_t vshmaddr =3D adi_set_version(shmaddr, SHMSIZE, 0x8); > + if (vshmaddr =3D=3D 0) { > + printf("ERROR: ISM cannot set version\n"); > + exit(1); > + } > + // test mmap > + int fd =3D open("/dev/zero", O_RDWR); > + if (fd < 0){ > + printf("ERROR:MMAP cannot open \n"); > + exit(1); > + } > + char *maddr =3D (char *)mmap(NULL,MAPSIZE,PROT_READ|PROT_WRITE, MAP_PRI= VATE, fd, 0); > + if (maddr =3D=3D (char *)-1) { > + printf("ERROR: mmap failed with an error:%d\n", errno); > + exit(1); > + } > + // enable ADI > + if (mprotect(shmaddr, MAPSIZE, PROT_READ|PROT_WRITE|PROT_ADI)) { > + perror("mprotect failed"); > + goto err_out; > + } > + if (memory_fill(maddr, MAPSIZE, 0xdeadbeaf) !=3D 0) { > + printf("ERROR:MMAP cannot fill memory\n"); > + exit(1); > + } > + caddr_t vmaddr =3D adi_set_version(maddr, MAPSIZE, 0x8); > + if (vmaddr =3D=3D 0) > + printf ("ERROR: MMAP cannot set version\n"); > + > + // test heap > + haddr =3D (char*) memalign(MAPSIZE, MAPSIZE); > + if (!haddr) { > + printf ("ERROR: HEAP cannot memalign\n"); > + } > + // enable ADI > + if (mprotect(shmaddr, MAPSIZE, PROT_READ|PROT_WRITE|PROT_ADI)) { > + perror("mprotect failed"); > + goto err_out; > + } > + > + if (memory_fill(haddr, MAPSIZE, 0xdeadbeaf) !=3D 0) { > + printf("ERROR:HEAP cannot fill memory\n"); > + exit(1); > + } > + adi_clr_version(haddr, MAPSIZE); > + /* Set some ADP version number */ > + caddr_t vaddr1, vaddr2, vaddr3, vaddr4; > + vaddr =3D adi_set_version(haddr, 64*2, 0x8); > + vaddr1 =3D adi_set_version(haddr+64*2, 64*2, 0x9); > + vaddr2 =3D adi_clr_version(haddr+64*4, 64*2); > + vaddr3 =3D adi_set_version(haddr+64*6, 64*2, 0xa); > + vaddr4 =3D adi_set_version(haddr+64*8, 64*10, 0x3); > + if (vaddr =3D=3D 0) { > + printf("ERROR: adi_set_version() failed to set version num\n"); > + exit(1); > + } > + char *versioned_p =3D vaddr; > + *versioned_p =3D 'a'; > + char *uvp =3D haddr; // unversioned pointer > + *uvp =3D 'b'; // version mismatch trap > + > + return (0); > +err_out: > + if (shmdt((const void *)shmaddr) !=3D 0) > + perror("Detach failure"); > + shmctl(shmid, IPC_RMID, NULL); > + exit(1); > +} > diff --git a/gdb/testsuite/gdb.arch/sparc64-adi.exp b/gdb/testsuite/gdb.a= rch/sparc64-adi.exp > new file mode 100644 > index 0000000..25ab183 > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/sparc64-adi.exp > @@ -0,0 +1,55 @@ > +# Copyright 2017 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# This file is part of the gdb testsuite. > + > +# Basic tests of examining/assigning ADI version tags, and reporting pre= cise mismatch. This line is too long. > + > +if ![istarget "sparc64*-*-linux*"] then { > + verbose "Skipping sparc64 ADI test." > + return 0 > +} > + > +set testfile sparc64-adi > +set srcfile ${testfile}.c > +set binfile ${objdir}/${subdir}/${testfile} Replace them with standard_testfile. > + > +set cflags "-g" > +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ > + [list additional_flags=3D$cflags libs=3D-ladi]] } { [list debug libs=3D-ladi] > + return -1 > +} > + > +if ![runto_main] then { > + untested "could not run to main" > + return -1 > +} > + > +gdb_test "break [gdb_get_line_number "line breakpoint here"]" \ > + "Breakpoint .* at .*${srcfile}.*" \ > + "set line breakpoint in main" > +gdb_continue_to_breakpoint "continue to line breakpoint in main" > + > +########################################## > +set newadi "7" > +gdb_test "adi x shmaddr" "" "examine ADI" Can you match the output? > +gdb_test "adi a/100 shmaddr=3D${newadi}" "" "assign ADI" Likewise. > +gdb_test "adi x/100 shmaddr" \ > +"0x\[0-9a-f\]+00:.*\t${newadi} ${newadi}.*" "examine new ADI" > +gdb_test "adi a/100 shmaddr=3D0x0" "" "reset ADI" > +gdb_test "continue" \ > + ".*Program received signal SIGSEGV.* > +.*ADI precise mismatch while accessing address.*" \ > + "continue to sigsegv" > diff --git a/gdb/testsuite/gdb.arch/sparc64-adilib.h b/gdb/testsuite/gdb.= arch/sparc64-adilib.h > new file mode 100755 > index 0000000..add026c > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/sparc64-adilib.h > @@ -0,0 +1,24 @@ Why do you need a header? --=20 Yao (=E9=BD=90=E5=B0=A7)