From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5324 invoked by alias); 9 Feb 2011 15:11:26 -0000 Mailing-List: contact archer-commits-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: Received: (qmail 5294 invoked by uid 306); 9 Feb 2011 15:11:25 -0000 Date: Wed, 09 Feb 2011 15:11:00 -0000 Message-ID: <20110209151125.5279.qmail@sourceware.org> From: tromey@sourceware.org To: archer-commits@sourceware.org Subject: [SCM] archer-tromey-multi-breakpoint-2: added $_strcmp and $_memcmp X-Git-Refname: refs/heads/archer-tromey-multi-breakpoint-2 X-Git-Reftype: branch X-Git-Oldrev: b1516d990e344bd827028ad11032eb89cf530e5d X-Git-Newrev: 4aabb4b780d0cd66dce3621f4c93e146e150d618 X-SW-Source: 2011-q1/txt/msg00096.txt.bz2 List-Id: The branch, archer-tromey-multi-breakpoint-2 has been updated via 4aabb4b780d0cd66dce3621f4c93e146e150d618 (commit) from b1516d990e344bd827028ad11032eb89cf530e5d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 4aabb4b780d0cd66dce3621f4c93e146e150d618 Author: Tom Tromey Date: Wed Feb 9 08:11:17 2011 -0700 added $_strcmp and $_memcmp ----------------------------------------------------------------------- Summary of changes: gdb/data-directory/Makefile.in | 3 +- gdb/python/lib/gdb/__init__.py | 1 + gdb/python/lib/gdb/function/strcmp.py | 67 +++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletions(-) create mode 100644 gdb/python/lib/gdb/function/strcmp.py First 500 lines of diff: diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in index 64c5bfe..596ca62 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -60,7 +60,8 @@ PYTHON_FILES = \ gdb/command/__init__.py \ gdb/command/multi.py \ gdb/command/pretty_printers.py \ - gdb/command/prompt.py + gdb/command/prompt.py \ + gdb/function/strcmp.py FLAGS_TO_PASS = \ "prefix=$(prefix)" \ diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py index d433110..0b15521 100644 --- a/gdb/python/lib/gdb/__init__.py +++ b/gdb/python/lib/gdb/__init__.py @@ -16,5 +16,6 @@ import gdb.command.pretty_printers import gdb.command.multi import gdb.command.prompt +import gdb.function.strcmp gdb.command.pretty_printers.register_pretty_printer_commands() diff --git a/gdb/python/lib/gdb/function/strcmp.py b/gdb/python/lib/gdb/function/strcmp.py new file mode 100644 index 0000000..dc7dd2d --- /dev/null +++ b/gdb/python/lib/gdb/function/strcmp.py @@ -0,0 +1,67 @@ +# Copyright (C) 2011 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 . + +import gdb + +class Strcmp(gdb.Function): + """A string-comparison function like C's strcmp. +Usage: $_strcmp (STR1, STR2, [LEN]) +With two arguments, compare strings until a terminating NUL character. +Return a negative value if STR1 is less than STR2, a positive +value if STR1 is greater than STR2, or zero if STR1 and STR2 are equal. +LEN, if specified, is the maximum number of characters to compare.""" + + def __init__(self): + super(Strcmp, self).__init__('_strcmp') + + def invoke(self, s1, s2, len = None): + i = 0 + while len is None or i < len: + c1 = s1[i] + c2 = s2[i] + if c1 < c2: + return -1 + elif c1 > c2: + return 1 + elif c1 == 0: + return 0 + i = i + 1 + return 0 + +class Memcmp(gdb.Function): + """A memory-comparison function like C's memcmp. +Usage: $_memcmp (MEM1, MEM2, LEN) +Bytewise compare two regions of memory. Return a negative value if +MEM1 is less than MEM2, a positive value if MEM1 is greater than MEM2, +or zero if MEM1 and MEM2 are equal. LEN is the maximum number of +bytes to compare.""" + + def __init__(self): + super(Memcmp, self).__init__('_memcmp') + + def invoke(self, s1, s2, len): + i = 0 + while i < len: + c1 = s1[i] + c2 = s2[i] + if c1 < c2: + return -1 + elif c1 > c2: + return 1 + i = i + 1 + return 0 + +Strcmp() +Memcmp() hooks/post-receive -- Repository for Project Archer.