From patchwork Thu Feb 23 10:22:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 19352 Received: (qmail 53099 invoked by alias); 23 Feb 2017 10:23:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 53069 invoked by uid 89); 23 Feb 2017 10:23:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=frozen, 794, manipulate X-HELO: mail-wm0-f67.google.com Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Feb 2017 10:23:00 +0000 Received: by mail-wm0-f67.google.com with SMTP id v77so1904844wmv.0 for ; Thu, 23 Feb 2017 02:23:00 -0800 (PST) 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:in-reply-to:references :user-agent:date:message-id:mime-version:content-transfer-encoding; bh=yCswjSbJTPPy4OFYInv113K5nFmmCdu2jGQo4ZwWpnI=; b=Gc9z7H7+rn4Gs6tav6TNgdFonBsuW+V5sdkPCQqWHChsXnOpTi6itzCfr90kkdRBzt pXbbUS12GeMJj8QnQ1+RyCnoSrfquXl8uljZDYzCoUxU682/TV5URxGcxyCOcjGuyuTb sc0FrPWlv0fZLKPF53rUdeNzI1uYITN9srfTpoNnDbOOx7hcnHHPBvkrITpPL3smA7DO hlhT590QwswiHGc9/U/HnJ73CbRGJeuouAIZgvrNsQ9TfIGYgPdVsAMAMKe3wa32qsNm KW4l9TBj9tRYReuT0Kv3pX22ossPiye46xr7mmbifpgk41rJ+VxmxjsbeQceCjyXaAnE srWQ== X-Gm-Message-State: AMke39k1uAjJXyfZb8KZN27inW+ZwLS4WtJgNSMxuVZbmJY+0Wo+QZmXfQIPjAXPymL8hw== X-Received: by 10.28.109.218 with SMTP id b87mr2063133wmi.52.1487845378157; Thu, 23 Feb 2017 02:22:58 -0800 (PST) Received: from E107787-LIN ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id v35sm5399303wrc.41.2017.02.23.02.22.57 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 23 Feb 2017 02:22:57 -0800 (PST) From: Yao Qi To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2 28/31] Use ui_file_as_string throughout more In-Reply-To: <1476968896-13600-1-git-send-email-palves@redhat.com> (Pedro Alves's message of "Thu, 20 Oct 2016 14:08:16 +0100") References: <1476839539-8374-1-git-send-email-palves@redhat.com> <1476968896-13600-1-git-send-email-palves@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Date: Thu, 23 Feb 2017 10:22:38 +0000 Message-ID: <86r32pb40h.fsf@gmail.com> MIME-Version: 1.0 X-IsSubscribed: yes Pedro Alves writes: Hi Pedro, > std::string as member of a struct, I needed to adjust > allocation/destruction of said struct to use new/delete instead of > xmalloc/xfree. > > diff --git a/gdb/varobj-iter.h b/gdb/varobj-iter.h > index bdbf661..1e7889b 100644 > --- a/gdb/varobj-iter.h > +++ b/gdb/varobj-iter.h > @@ -19,7 +19,7 @@ > typedef struct varobj_item > { > /* Name of this item. */ > - char *name; > + std::string name; > > /* Value of this item. */ > struct value *value; > @@ -67,6 +67,6 @@ struct varobj_iter_ops > if ((ITER) != NULL) \ > { \ > (ITER)->ops->dtor (ITER); \ > - xfree (ITER); \ > + delete (ITER); \ We don't need to use "delete" for varobj_iter, because you didn't add std::string member in varobj_iter. This change causes an ASAN error, -var-create container @ c^M =================================================================^M ^[[1m^[[31m==12975==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x603000085e40^M ^[[1m^[[0m #0 0x2b8ce74d15d7 in operator delete(void*) (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x555d7)^M #1 0xc13d3c in update_dynamic_varobj_children /home/yao/SourceCode/gnu/gdb/git/gdb/varobj.c:786^M #2 0xc1425f in varobj_get_num_children(varobj*) /home/yao/SourceCode/gnu/gdb/git/gdb/varobj.c:846^M #3 0x59ffeb in print_varobj /home/yao/SourceCode/gnu/gdb/git/gdb/mi/mi-cmd-var.c:61^M #4 0x5a0689 in mi_cmd_var_create(char*, char**, int) /home/yao/SourceCode/gnu/gdb/git/gdb/mi/mi-cmd-var.c:145^M #5 0x5b5ac9 in mi_cmd_execute /home/yao/SourceCode/gnu/gdb/git/gdb/mi/mi-main.c:2295^M #6 0x5b3de0 in captured_mi_execute_command /home/yao/SourceCode/gnu/gdb/git/gdb/mi/mi-main.c:1997^M ..... ^M ^[[1m^[[32m0x603000085e40 is located 0 bytes inside of 32-byte region [0x603000085e40,0x603000085e60)^M ^[[1m^[[0m^[[1m^[[35mallocated by thread T0 here:^[[1m^[[0m^M #0 0x2b8ce74d0862 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54862)^M #1 0x80df7f in xmalloc /home/yao/SourceCode/gnu/gdb/git/gdb/common/common-utils.c:43^M #2 0x6364ec in py_varobj_iter_new /home/yao/SourceCode/gnu/gdb/git/gdb/python/py-varobj.c:154^M #3 0x636710 in py_varobj_get_iterator(varobj*, _object*) /home/yao/SourceCode/gnu/gdb/git/gdb/python/py-varobj.c:188^M #4 0xc13580 in varobj_get_iterator /home/yao/SourceCode/gnu/gdb/git/gdb/varobj.c:712^M #5 0xc138fa in update_dynamic_varobj_children /home/yao/SourceCode/gnu/gdb/git/gdb/varobj.c:750^M #6 0xc1425f in varobj_get_num_children(varobj*) /home/yao/SourceCode/gnu/gdb/git/gdb/varobj.c:846^M reverting the change above fixes the error. We can also C++-fy varobj_iter, but I'd like to do in another patch. How is the patch below? > } \ > } while (0) > diff --git a/gdb/varobj.h b/gdb/varobj.h > index 6b9a71f..7f4aad2 100644 > --- a/gdb/varobj.h > +++ b/gdb/varobj.h > @@ -86,22 +86,22 @@ struct varobj_dynamic; > > /* Every variable in the system has a structure of this type defined > for it. This structure holds all information necessary to manipulate > - a particular object variable. Members which must be freed are noted. */ > + a particular object variable. */ > struct varobj > { > - /* Alloc'd name of the variable for this object. If this variable is a > + /* Name of the variable for this object. If this variable is a > child, then this name will be the child's source name. > (bar, not foo.bar). */ > /* NOTE: This is the "expression". */ > - char *name; > + std::string name; > > - /* Alloc'd expression for this child. Can be used to create a > - root variable corresponding to this child. */ > - char *path_expr; > + /* Expression for this child. Can be used to create a root variable > + corresponding to this child. */ > + std::string path_expr; > > - /* The alloc'd name for this variable's object. This is here for > + /* The name for this variable's object. This is here for > convenience when constructing this object's children. */ > - char *obj_name; > + std::string obj_name; > > /* Index of this variable in its parent or -1. */ > int index; > @@ -137,7 +137,7 @@ struct varobj > int updated; > > /* Last print value. */ > - char *print_value; > + std::string print_value; > > /* Is this variable frozen. Frozen variables are never implicitly > updated by -var-update * > @@ -170,18 +170,15 @@ struct lang_varobj_ops > /* The number of children of PARENT. */ > int (*number_of_children) (const struct varobj *parent); > > - /* The name (expression) of a root varobj. The returned value must be freed > - by the caller. */ > - char *(*name_of_variable) (const struct varobj *parent); > + /* The name (expression) of a root varobj. */ > + std::string (*name_of_variable) (const struct varobj *parent); > > - /* The name of the INDEX'th child of PARENT. The returned value must be > - freed by the caller. */ > - char *(*name_of_child) (const struct varobj *parent, int index); > + /* The name of the INDEX'th child of PARENT. */ > + std::string (*name_of_child) (const struct varobj *parent, int index); > > /* Returns the rooted expression of CHILD, which is a variable > - obtain that has some parent. The returned value must be freed by the > - caller. */ > - char *(*path_expr_of_child) (const struct varobj *child); > + obtain that has some parent. */ > + std::string (*path_expr_of_child) (const struct varobj *child); > > /* The ``struct value *'' of the INDEX'th child of PARENT. */ > struct value *(*value_of_child) (const struct varobj *parent, int index); > @@ -189,10 +186,9 @@ struct lang_varobj_ops > /* The type of the INDEX'th child of PARENT. */ > struct type *(*type_of_child) (const struct varobj *parent, int index); > > - /* The current value of VAR. The returned value must be freed by the > - caller. */ > - char *(*value_of_variable) (const struct varobj *var, > - enum varobj_display_formats format); > + /* The current value of VAR. */ > + std::string (*value_of_variable) (const struct varobj *var, > + enum varobj_display_formats format); > > /* Return non-zero if changes in value of VAR must be detected and > reported by -var-update. Return zero if -var-update should never -- Yao (齐尧) From 71dc64a061cfb1ec57b753e495c02665827c7a01 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Thu, 23 Feb 2017 09:29:48 +0000 Subject: [PATCH] Use xfree rather than delete for varobj_iter ASAN reports an error, -var-create container @ c^M =================================================================^M ^[[1m^[[31m==21639==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x6030000805c0^M ^[[1m^[[0m #0 0x7f2449b01b2a in operator delete(void*) (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99b2a)^M #1 0xbb601d in update_dynamic_varobj_children ../../binutils-gdb/gdb/varobj.c:794^M #2 0xbb6556 in varobj_get_num_children(varobj*) ../../binutils-gdb/gdb/varobj.c:854^M #3 0x580cb4 in print_varobj ../../binutils-gdb/gdb/mi/mi-cmd-var.c:61^M #4 0x58138b in mi_cmd_var_create(char*, char**, int) ../../binutils-gdb/gdb/mi/mi-cmd-var.c:145^M #5 0x5967ce in mi_cmd_execute ../../binutils-gdb/gdb/mi/mi-main.c:2301^M #6 0x594b05 in captured_mi_execute_command ../../binutils-gdb/gdb/mi/mi-main.c:2001 .... ^M ^[[1m^[[32m0x6030000805c0 is located 0 bytes inside of 32-byte region [0x6030000805c0,0x6030000805e0)^M ^[[1m^[[0m^[[1m^[[35mallocated by thread T0 here:^[[1m^[[0m^M #0 0x7f2449b00602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)^M #1 0x7d1596 in xmalloc ../../binutils-gdb/gdb/common/common-utils.c:43^M #2 0x604176 in py_varobj_iter_new ../../binutils-gdb/gdb/python/py-varobj.c:159^M #3 0x6042da in py_varobj_get_iterator(varobj*, _object*) ../../binutils-gdb/gdb/python/py-varobj.c:198^M #4 0xbb5806 in varobj_get_iterator ../../binutils-gdb/gdb/varobj.c:720^M #5 0xbb5b9b in update_dynamic_varobj_children ../../binutils-gdb/gdb/varobj.c:758^M gdb: 2017-02-23 Yao Qi * varobj-iter.h (varobj_iter_delete): Call xfree instead of delete. diff --git a/gdb/varobj-iter.h b/gdb/varobj-iter.h index 34182e0..7eed4f1 100644 --- a/gdb/varobj-iter.h +++ b/gdb/varobj-iter.h @@ -67,6 +67,6 @@ struct varobj_iter_ops if ((ITER) != NULL) \ { \ (ITER)->ops->dtor (ITER); \ - delete (ITER); \ + xfree (ITER); \ } \ } while (0)