From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6389 invoked by alias); 16 Jul 2009 10:18:19 -0000 Received: (qmail 6380 invoked by uid 22791); 16 Jul 2009 10:18:18 -0000 X-SWARE-Spam-Status: No, hits=2.0 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_12,J_CHICKENPOX_21,KAM_STOCKTIP,OBSCURED_EMAIL,SARE_RAND_2,SPF_PASS X-Spam-Check-By: sourceware.org Received: from rv-out-0708.google.com (HELO rv-out-0708.google.com) (209.85.198.241) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Jul 2009 10:18:11 +0000 Received: by rv-out-0708.google.com with SMTP id b17so1106rvf.48 for ; Thu, 16 Jul 2009 03:18:09 -0700 (PDT) Received: by 10.140.157.12 with SMTP id f12mr4920425rve.112.1247739489665; Thu, 16 Jul 2009 03:18:09 -0700 (PDT) Received: from bibi.branda.to (61-30-10-70.static.tfn.net.tw [61.30.10.70]) by mx.google.com with ESMTPS id k2sm9442366rvb.22.2009.07.16.03.17.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 16 Jul 2009 03:18:09 -0700 (PDT) Received: from bibi.branda.to (localhost [127.0.0.1]) by bibi.branda.to (8.14.3/8.14.3) with ESMTP id n6GAIM57009471; Thu, 16 Jul 2009 18:18:32 +0800 (CST) (envelope-from thinker@localhost.my.domain) Received: (from thinker@localhost) by bibi.branda.to (8.14.3/8.14.3/Submit) id n6GAIMet009468; Thu, 16 Jul 2009 18:18:22 +0800 (CST) (envelope-from thinker) From: User Thinker MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <19038.65134.58926.218902@bibi.branda.to> Date: Thu, 16 Jul 2009 19:07:00 -0000 To: gdb-patches@sourceware.org Subject: Get backtrace at PLT and stepi into PLT Cc: mokoko-group@googlegroups.com 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 X-SW-Source: 2009-07/txt/msg00407.txt.bz2 Hi all, I have a patch that makes GDB can properly stepi into PLT for ARM Thumb instruction. The patch also allow GDB to perform backtrace at PLT. If you have a caller function, compiled with Thumb instruction set with GCC, calls another callee function in another file and you link the object containing caller to a ELF shared object, GNU ld will generate a special trampoline in PLT section for the callee function which is not in the same shared boject. If you try to stepi on bl instruction of caller and expect that GDB would stop at first instruction of the trampoline, you would be disappointed. LD generates a trampoline that starts with 4 bytes of Thumb instruction (2 instructions) followed by 14 bytes of ARM instructins (3 instructions). The Thumb instructions are braches that branch to first instruction of the ARM instructions and clear T flags. It means switching processor to ARM instruction set from Thumb instruction set. It means GDB should put a invalid instruction of Thumb version at base address of the trampoline. But, it actually puts ARM version one. I have checked GDB source code for this issue. GDB check flags in symbol that contain memory space that breakpoint was setted at. If the symbol is flaged as Thumb, it uses Thumb version invalid instruction code, or it would use ARM version. It is reasonable. But, the trampoline in PLT contains both types of instructions. And, the result of checking is the block where the trampoline is in is not Thumb. The solution is to check bl instructions in Thumb caller function. If the bl instruction will not transit processor to ARM from Thumb instruction set, we should still use Thumb version despite what is got from the symbol. If you try to backtrace stack when GDB stop at PLT, you would get nothing. It is because no any unwinder can handle code in PLT. I add and register a tramp_frame for ARM Linux architecture, and add a new frame type "GHOST_FRAME". The tramp_frame can handle PLT trampoline for ARM Thumb. And, I can get backtrace when GDB stop an inferior at PLT. Following is changelog of the patch and patch itself. 2009-07-16 Thinker @ 0xlab * arm-linux-tdep.c (arm_eabi_linux_plt_tramp_frame): Add a new tramp_frame for ARM Linux PLT code with GHOST_FRAME type. * frame.h (enum frame_type): Add new frame_type GHOST_FRAME. * frame.c (get_prev_frame): Likewise. * arm-tdep.c (thumb_get_next_pc): Fix the bug that GDB does not make a breakpoint correctly for ARM. begin 644 arm-plt.diff.gz M'XL(`#OJ7DH``YU7;4_;2!#^C'_%E)-Z`3O43D*20JDH$"A5"%62ZGKWQ?++ M.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