From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by sourceware.org (Postfix) with ESMTPS id 750203858D1E for ; Tue, 20 Jun 2023 12:49:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 750203858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687265386; x=1718801386; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=lQLJOKdXxYt8FiUiCBJ2KG+YeIhH1DNwVbBnYwHgdm4=; b=kHsaERhARU3zikonWC8MJeyspeqwZ/vA5G9sC1DoHRN2epwzQz8hlf4J YPZGDoJkum9wkFT71CTi5XwnpJ4Rm05V/4OQ4Dz9VfkOc9p2L3mluDs3l UHVisdixLJVYpXcOkIjdyHejZXQNZ8EfIL5RwrJY2tkS0t/prce+TFM1B SaRE2vx7LN6CXYtGhhCycSE9HjNEnXkYGrrhtljTEWSfKQoQ53ky9PlZm 6nogUDl2FprFY/UbgfvMrYqKabyNB0RFqXSpv3+vCMld3bxVAvIpPt5gi HYyTdTRYa8ky+JBThpANRhJFuJ/pbYc3XxIoBbDm1Zq5DunUHmLvhrgdt g==; X-IronPort-AV: E=McAfee;i="6600,9927,10746"; a="425804014" X-IronPort-AV: E=Sophos;i="6.00,257,1681196400"; d="scan'208";a="425804014" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 05:49:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10746"; a="838193768" X-IronPort-AV: E=Sophos;i="6.00,257,1681196400"; d="scan'208";a="838193768" Received: from ultl2604.iul.intel.com (HELO localhost) ([172.28.48.47]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2023 05:49:44 -0700 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Subject: [PATCH] gdbserver: extract code out of regcache's registers_to_string Date: Tue, 20 Jun 2023 14:49:33 +0200 Message-Id: <20230620124933.2792496-1-tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.2 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Extract out code from regcache's registers_to_string to dump a single register value to a string. Reuse the new method in 'collect_register_as_string' so that unavailable registers are dumped as 'xx...x' instead of arbitrary values. --- gdbserver/regcache.cc | 34 +++++++++++++++++++--------------- gdbserver/regcache.h | 5 +++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 0b1141662ac..82accdb89fc 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -205,29 +205,34 @@ find_register_by_number (const struct target_desc *tdesc, int n) return tdesc->reg_defs[n]; } +static unsigned char *register_data (const regcache *regcache, int n); + #ifndef IN_PROCESS_AGENT +void +register_to_string (struct regcache *regcache, int n, char *buf) +{ + int reg_size = register_size (regcache->tdesc, n); + + if (regcache->register_status[n] == REG_VALID) + bin2hex (register_data (regcache, n), buf, reg_size); + else + memset (buf, 'x', reg_size * 2); + + buf += reg_size * 2; + *buf = '\0'; +} + void registers_to_string (struct regcache *regcache, char *buf) { - unsigned char *registers = regcache->registers; const struct target_desc *tdesc = regcache->tdesc; for (int i = 0; i < tdesc->reg_defs.size (); ++i) { - if (regcache->register_status[i] == REG_VALID) - { - bin2hex (registers, buf, register_size (tdesc, i)); - buf += register_size (tdesc, i) * 2; - } - else - { - memset (buf, 'x', register_size (tdesc, i) * 2); - buf += register_size (tdesc, i) * 2; - } - registers += register_size (tdesc, i); + register_to_string (regcache, i, buf); + buf += register_size (tdesc, i) * 2; } - *buf = '\0'; } void @@ -472,8 +477,7 @@ regcache_raw_get_unsigned_by_name (struct regcache *regcache, void collect_register_as_string (struct regcache *regcache, int n, char *buf) { - bin2hex (register_data (regcache, n), buf, - register_size (regcache->tdesc, n)); + register_to_string (regcache, n, buf); } void diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h index 7248bcf5808..fba9498712a 100644 --- a/gdbserver/regcache.h +++ b/gdbserver/regcache.h @@ -93,6 +93,11 @@ void regcache_invalidate (void); void regcache_release (void); +/* Convert the register N's value to a string in the currently + specified remote format. */ + +void register_to_string (regcache *regcache, int n, char *buf); + /* Convert all registers to a string in the currently specified remote format. */ -- 2.25.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928