From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11790 invoked by alias); 12 Nov 2013 22:42:29 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 11779 invoked by uid 89); 12 Nov 2013 22:42:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL,BAYES_50,RDNS_NONE,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ee0-f43.google.com Received: from Unknown (HELO mail-ee0-f43.google.com) (74.125.83.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 12 Nov 2013 22:42:27 +0000 Received: by mail-ee0-f43.google.com with SMTP id b47so3442188eek.2 for ; Tue, 12 Nov 2013 14:42:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=DbfEmHzUL1mer4ItjQfQnhb8XOEz+hDSLGqzCQmeX/8=; b=VynVuv9Xil6zwmkF29ZaY5jOuwf2EMN5q4V+DY+XY6HG6eG6p5goquPtDQGOGpdqP6 cEHGbmEMDTfVeKJDW/a1Yr7b5jeS2cAYNNqth2Am5GXIS4ZNSrzXOkfcStmD3qZenhrD wjUJh332EHh8CCXhtwnah99kSaJF2TUKQXFTE8JyKG6Bqcf4oVhOwEmCB3eVlx5riQNl tsWcAzrJ4VNnJoIV0U/BDsUiknNckisraPttqENU2eIwWP+G45qgORKZAAyG6xwy9EkA vWpurxHQGpPMR4c99CiVvrH/ErAx+aMSSCfPZcjo3RGLysBTeWLIxuh5jyP04kktZKig JWIw== X-Gm-Message-State: ALoCoQmxO+OUsb1X/9SyG45W6Kx525ut+CIzxA2Asx8C1Gs1mnAunb/qu+kdVplEl4A81TM+mTVXje8T/myhohMAS9D/xpEfOFg8qj16qL8uLNLX0uz5ZSEUIv+dwzmp0lXtphb4/0Y/HTln/6w4fOtarCAVKchXWk2oeY0PYOsDXJas82W/TpcoXAv4ygSCVZ4wfONXNHQj MIME-Version: 1.0 X-Received: by 10.15.32.73 with SMTP id z49mr9722530eeu.27.1384296140552; Tue, 12 Nov 2013 14:42:20 -0800 (PST) Received: by 10.223.103.4 with HTTP; Tue, 12 Nov 2013 14:42:20 -0800 (PST) In-Reply-To: References: Date: Tue, 12 Nov 2013 22:42:00 -0000 Message-ID: Subject: Re: back into the thread.... From: Sterling Augustine To: Mark Manning Cc: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00050.txt.bz2 This feature clearly works. On Tue, Nov 12, 2013 at 2:08 PM, Mark Manning wrote: > Got a reply from someone here about my problems with gdb but i cannot > figure out how to reply all and googles reply always top posts my > replies. Also i still have the same issue in that i cannot execute > code that is not part of the original executables object. any > additional code written into memory by my compiler is not executable > yet the person who replied to me said that it SHOULD be possible as he > does it all the time. > > this is a version of gdb running on an arm target (beagle board xm) > under a gentoo linux install - is this a bug injected into gdb by some > gentoo snafu? If gdb doesn't think the memory is accessible, then it probably isn't. The following test-case works perfectly well for gdb. You may want to be sure that you are following all the correct steps in your code generator, particularly the posix_memalign and mprotect. Otherwise your code will take an unexpected segfault. I can set a breakpoint at dst and stepi through it no problem. The contents of bytes comes from compiling int foo(int x) { return x; } at O2 and then copying the resulting bytes into the array. You would want to do something similar to get ARM results. Be sure it doesn't have relocations. ===== #include #include #include #include #include const char bytes[] = { 0x89, 0xf8, 0xc3 }; #define EXEC_BYTES sizeof(bytes) typedef int(*function_ptr)(int); int main(int argc, char *argv[]) { int test_val; int return_val; function_ptr dst = malloc(EXEC_BYTES); if (posix_memalign((void **) &dst, 4096*8, EXEC_BYTES) != 0) { printf("can't allocate.\n"); exit (-1); } if (mprotect(dst, EXEC_BYTES, PROT_READ|PROT_WRITE|PROT_EXEC) != 0) { printf("can't mprotect\n"); exit (-1); } if (argc > 1) test_val = atoi(argv[1]); memcpy(dst, bytes, EXEC_BYTES); return_val = dst(test_val); printf("return val was %d\n", return_val); return 0; }