From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25240 invoked by alias); 24 Apr 2015 21:54:53 -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 25226 invoked by uid 89); 24 Apr 2015 21:54:53 -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-pa0-f41.google.com Received: from mail-pa0-f41.google.com (HELO mail-pa0-f41.google.com) (209.85.220.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 24 Apr 2015 21:54:51 +0000 Received: by pabtp1 with SMTP id tp1so59449505pab.2 for ; Fri, 24 Apr 2015 14:54:50 -0700 (PDT) X-Received: by 10.70.43.10 with SMTP id s10mr782687pdl.57.1429912489974; Fri, 24 Apr 2015 14:54:49 -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 iz2sm11987607pbc.37.2015.04.24.14.54.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Apr 2015 14:54:48 -0700 (PDT) Message-ID: <553ABBA4.40505@gmail.com> Date: Fri, 24 Apr 2015 21:54: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: libffi-discuss@sourceware.org Subject: *printf functions Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2015/txt/msg00060.txt.bz2 Hi, My number 1 need is for calling printf functions based upon derived information. Since there is no widespread argument vector implementations of *printf (the abortive "snprintfv" library excepted due to the "widespread" requirement), I need to construct calls to the snprintf function. I know about the vararg caveats, but there is also the notation that "it often works anyway", so I was hoping that it would for snprintf under Linux on an x86-64: > $ /lib64/libc.so.6 > GNU C Library (GNU libc) stable release version 2.18 (git ), by Roland McGrath et al. > Copyright (C) 2013 Free Software Foundation, Inc. > $ gcc --version|head -n2 > gcc (SUSE Linux) 4.8.1 20130909 [gcc-4_8-branch revision 202388] > Copyright (C) 2013 Free Software Foundation, Inc. So, I constructed this call > Breakpoint 1, print_one_event (evd=0x7ffff5ecc088) at evt/src/event-print.c:181 > 181 ffi_call(&cif, snprintf_fn, &snprintf_res, values); > (gdb) p cif > $1 = {abi = FFI_UNIX64, nargs = 5, arg_types = 0x663c1f0, > rtype = 0x40e490 , bytes = 0, flags = 9} > (gdb) p cif.arg_types[0] > $2 = (ffi_type *) 0x40e510 > (gdb) p cif.arg_types[1] > $3 = (ffi_type *) 0x40e4d0 > (gdb) p cif.arg_types[2] > $4 = (ffi_type *) 0x40e510 > (gdb) p cif.arg_types[3] > $5 = (ffi_type *) 0x40e490 > (gdb) p cif.arg_types[4] > $6 = (ffi_type *) 0x40e490 [...] > (gdb) p (char *)values[0] > $10 = 0x7fffffffc6b4 "" > (gdb) p *(int*)values[1] > $11 = 4044 > (gdb) p (char *)values[2] > $12 = 0x40e360 "Allocated sblock_id=%d for band_id=%d\n" > (gdb) p *(int*)values[3] > $13 = 1 > (gdb) p *(int*)values[4] > $14 = 1 so it all seems right (is it?), but clearly I would not be writing if it went well. Is my hope to use libffi for calling snprintf a vein one? Thank you. > (gdb) c > Continuing. > > Program received signal SIGSEGV, Segmentation fault. > 0x00007ffff7446892 in vsnprintf () from /lib64/libc.so.6 > (gdb) bt > #0 0x00007ffff7446892 in vsnprintf () from /lib64/libc.so.6 > #1 0x00007ffff7424ff2 in snprintf () from /lib64/libc.so.6 > #2 0x000000000040b660 in ffi_call_unix64 () at ../src/x86/unix64.S:76 > #3 0x000000000040b02f in ffi_call (cif=0x7fffffffc640, > fn=0x401250 , rvalue=0x7fffffffc66c, avalue=0x663c230) > at ../src/x86/ffi64.c:525