From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 56879 invoked by alias); 25 Apr 2015 17:31:45 -0000 Mailing-List: contact libffi-discuss-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libffi-discuss-owner@sourceware.org Received: (qmail 56867 invoked by uid 89); 25 Apr 2015 17:31:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f176.google.com Received: from mail-pd0-f176.google.com (HELO mail-pd0-f176.google.com) (209.85.192.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sat, 25 Apr 2015 17:31:43 +0000 Received: by pdbqa5 with SMTP id qa5so80606272pdb.1 for ; Sat, 25 Apr 2015 10:31:41 -0700 (PDT) X-Received: by 10.68.206.101 with SMTP id ln5mr7693614pbc.97.1429983101532; Sat, 25 Apr 2015 10:31:41 -0700 (PDT) Received: from [172.16.16.2] (adsl-75-18-230-75.dsl.pltn13.sbcglobal.net. [75.18.230.75]) by mx.google.com with ESMTPSA id om4sm14563144pdb.68.2015.04.25.10.31.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Apr 2015 10:31:40 -0700 (PDT) Message-ID: <553BCF7A.8030502@gmail.com> Date: Sat, 25 Apr 2015 17:31:00 -0000 From: Bruce Korb User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Richard Henderson , libffi-discuss@sourceware.org Subject: Re: *printf functions References: <553ABBA4.40505@gmail.com> <553AD0A8.2040602@redhat.com> In-Reply-To: <553AD0A8.2040602@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2015/txt/msg00063.txt.bz2 On 04/24/15 16:24, Richard Henderson wrote: > On 04/24/2015 11:54 AM, Bruce Korb wrote: >> Is my hope to use libffi for calling snprintf a vein one? > > As long as you used ffi_prep_cif_var instead of ffi_prep_cif it will work. You > didn't quote enough of your source to see that part. OK, here's the more complete debug session: 148 ffi_type ** args = assemble_ffi_args(evd, edsc, &values); (gdb) n 153 values[0] = buf; (gdb) 154 args[0] = &ffi_type_pointer; (gdb) 156 values[1] = &spc; (gdb) 157 args[1] = (sizeof(size_t) == sizeof(u64)) (gdb) 160 values[2] = UNCONST(ev_fmt); (gdb) 161 args[2] = &ffi_type_pointer; (gdb) 163 if (ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 3, edsc->edsc_argct + 3, (gdb) 167 ffi_call(&cif, fn, &ret_val, values); (gdb) p cif $1 = {abi = FFI_UNIX64, nargs = 5, arg_types = 0x8710510, rtype = 0x613dd0 , bytes = 0, flags = 9} (gdb) p cif.arg_types[0] $2 = (ffi_type *) 0x613db0 (gdb) p cif.arg_types[1] $3 = (ffi_type *) 0x613d90 (gdb) p cif.arg_types[2] $4 = (ffi_type *) 0x613db0 (gdb) p cif.arg_types[3] $5 = (ffi_type *) 0x613dd0 (gdb) p cif.arg_types[4] $6 = (ffi_type *) 0x613dd0 (gdb) p (char *)values[0] $7 = 0x7fffffffc6b4 "" (gdb) p *(unsigned long *)values[1] $8 = 4044 (gdb) p (char *)values[2] $9 = 0x40fe70 "Allocated sblock_id=%d for band_id=%d" (gdb) p *(unsigned *)values[3] $10 = 1 (gdb) p *(unsigned *)values[4] $11 = 1 (gdb) p fn $12 = (void *) 0x4012d0 So I put together the "var" portion of the arg list with "assemble_ffi_args()" and upon return insert the three fixed args (destination, size and format string). I've printed out the "cif", the arg types and the arg values and they all look correct. I will now press "n" and "" and have a seg fault: > (gdb) n > > Program received signal SIGSEGV, Segmentation fault. > 0x00007ffff7455892 in vsnprintf () from /lib64/libc.so.6 :( This would make for a perfect example for the use of ffi_prep_cif_var() :) > (gdb) bt > #0 0x00007ffff7455892 in vsnprintf () from /lib64/libc.so.6 > #1 0x00007ffff7433ff2 in snprintf () from /lib64/libc.so.6 > #2 0x00007ffff7796cd8 in ffi_call_unix64 () from /usr/lib64/libffi.so.4 > #3 0x00007ffff7796729 in ffi_call () from /usr/lib64/libffi.so.4 P.S. I also have a /usr/local/lib64/libffi.a built with "-O0 -ggdb3 -gdwarf-2", if more debugging stuff is useful. > Breakpoint 1, format_one_event (buf=0x7fffffffc6b4 "", spc=4044, > fn=0x401250 , evd=0x7ffff5ecc088, > ev_fmt=0x411630 "Allocated sblock_id=%d for band_id=%d", > edsc=0x615a98 ) at evt/src/event-print.c:148 > 148 ffi_type ** args = assemble_ffi_args(evd, edsc, &values); > (gdb) c > Continuing. > > Breakpoint 2, ffi_call_unix64 () at ../src/x86/unix64.S:49 > 49 movq (%rsp), %r10 /* Load return address. */