From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13298 invoked by alias); 19 Jun 2013 11:19:15 -0000 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 Received: (qmail 13285 invoked by uid 89); 19 Jun 2013 11:19:15 -0000 X-Spam-SWARE-Status: No, score=-8.1 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS,TW_RG autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 19 Jun 2013 11:19:14 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5JBJCSt027529 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 19 Jun 2013 07:19:12 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r5JBJA8m000368; Wed, 19 Jun 2013 07:19:11 -0400 Message-ID: <51C193AE.7010608@redhat.com> Date: Wed, 19 Jun 2013 11:43:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130514 Thunderbird/17.0.6 MIME-Version: 1.0 To: lgustavo@codesourcery.com CC: "'gdb-patches@sourceware.org'" Subject: Re: [PATCH, gdbsim] Avoid silly crash when no binary is loaded References: <51C0C7E3.1030603@codesourcery.com> In-Reply-To: <51C0C7E3.1030603@codesourcery.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-SW-Source: 2013-06/txt/msg00483.txt.bz2 On 06/18/2013 09:49 PM, Luis Machado wrote: > Hi, > > This patch prevents the long-standing crash scenario where we start > gdbsim and "run" without any binaries. Warnings are issued, but those > don't prevent the simulator from proceeding with garbage data. Which sim and backtrace? I suspect this to be sim/arch dependent. > > Replacing those warnings with error calls seems to be the most > appropriate here. Well, the code seems to have been written like that for a reason. Real boards can be powered on with no real program in memory too... > if (exec_file == 0 || exec_bfd == 0) > - warning (_("No executable file specified.")); > + error (_("No executable file specified.")); > if (!sim_data->program_loaded) > - warning (_("No program loaded.")); > + error (_("No program loaded.")); > There's code just below that does: > if (remote_debug) > printf_filtered ("gdbsim_create_inferior: exec_file \"%s\", args \"%s\"\n", ... > if (exec_file != NULL) > { > len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10; > arg_buf = (char *) alloca (len); > arg_buf[0] = '\0'; > strcat (arg_buf, exec_file); > strcat (arg_buf, " "); > strcat (arg_buf, args); > argv = gdb_buildargv (arg_buf); > make_cleanup_freeargv (argv); > } > else > argv = NULL; So if we error out, then these NULL checks are now dead. And e.g., the bfin sim, at sim/bfin/interp.c:sim_create_inferior allows NULL exec_bfd: SIM_RC sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env) { SIM_CPU *cpu = STATE_CPU (sd, 0); SIM_ADDR addr; /* Set the PC. */ if (abfd != NULL) addr = bfd_get_start_address (abfd); else addr = 0; sim_pc_set (cpu, addr); -- Pedro Alves