From nobody Tue Feb 10 04:16:00 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609771058; cv=none; d=zohomail.com; s=zohoarc; b=cvSmn5/sFu9agkfxuRYbglDN6qIesQxwGC+OzxCL7nYqMGAdd49PDfwnwwLoW+c9MKzmwTjfKWutpmthKq6cJcv8L1Ly68UL8dhJSxy6TeM8Tedb9yNfF/p8ejwlf4dOp1+uhKG0u+ObuIb87pPAHa8/uA7Arls3gE4zfTN7T7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609771058; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9vee9K26BvrmT5nT/Jr7ylwdherUzohr7+W+KBGF2G4=; b=Lcg/BmyIB+SG7dldXOWMFxgpR581p53Dey7WcikwLoi5291alILXFnp/KA6nRiyNXp9iEh35okAF+uzfTrOe8zBC3tToVQbCrXck2I1jwyTsSNYtBh1NvPH9Lf+AdIr/zAHblgW4Hm/fR3EqmS7yprSTGlsvmG5+gbW8zZw9Uxg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1609771058709986.1214089099366; Mon, 4 Jan 2021 06:37:38 -0800 (PST) Received: from localhost ([::1]:50286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwQzJ-0002bS-JS for importer@patchew.org; Mon, 04 Jan 2021 09:37:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwQuL-0006U4-A0 for qemu-devel@nongnu.org; Mon, 04 Jan 2021 09:32:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kwQuI-00013y-6d for qemu-devel@nongnu.org; Mon, 04 Jan 2021 09:32:29 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-402-e_c4o7ryO4G7PC-Y2Yv-kg-1; Mon, 04 Jan 2021 09:32:17 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A942C1842140; Mon, 4 Jan 2021 14:32:16 +0000 (UTC) Received: from localhost (ovpn-113-37.ams2.redhat.com [10.36.113.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 456D06F818; Mon, 4 Jan 2021 14:32:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609770743; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9vee9K26BvrmT5nT/Jr7ylwdherUzohr7+W+KBGF2G4=; b=Xq0AddVTW3INT7gKBSSOoOwoDpTPUgCVPFPeJIGOzASNpcQvH0AkU74v0PV0K0NtYKlCYb fBdTozoUR7d4bM4sA9MYO5YoyYxsg2nZaGk/SplnSPFqzLAqdWvewk78kcsTjeOlKZo5xp K1t++sAamh9y9EZ1YL8EMwSidDgDf5k= X-MC-Unique: e_c4o7ryO4G7PC-Y2Yv-kg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PULL 5/5] tracetool: show trace-events filename/lineno in fmt string errors Date: Mon, 4 Jan 2021 14:31:54 +0000 Message-Id: <20210104143154.462212-6-stefanha@redhat.com> In-Reply-To: <20210104143154.462212-1-stefanha@redhat.com> References: <20210104143154.462212-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.243, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefan Hajnoczi , Eduardo Habkost , qemu-block@nongnu.org, Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The compiler encounters trace event format strings in generated code. Format strings are error-prone and therefore clear compiler errors are important. Use the #line directive to show the trace-events filename and line number in format string errors: https://gcc.gnu.org/onlinedocs/gcc-10.2.0/cpp/Line-Control.html For example, if the cpu_in trace event's %u is changed to %p the following error is reported: trace-events:29:18: error: format =E2=80=98%p=E2=80=99 expects argument o= f type =E2=80=98void *=E2=80=99, but argument 7 has type =E2=80=98unsigned = int=E2=80=99 [-Werror=3Dformat=3D] Line 29 in trace-events is where cpu_in is defined. This works for any trace-events file in the QEMU source tree and the correct path is displayed. Unfortunately there does not seem to be a way to set the column, so "18" is not the right character on that line. Suggested-by: Peter Maydell Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Maydell Message-Id: <20200827142915.108730-5-stefanha@redhat.com> --- scripts/tracetool/backend/ftrace.py | 4 ++++ scripts/tracetool/backend/log.py | 4 ++++ scripts/tracetool/backend/syslog.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backen= d/ftrace.py index e9844dd335..5fa30ccc08 100644 --- a/scripts/tracetool/backend/ftrace.py +++ b/scripts/tracetool/backend/ftrace.py @@ -33,8 +33,10 @@ def generate_h(event, group): ' int unused __attribute__ ((unused));', ' int trlen;', ' if (trace_event_get_state(%(event_id)s)) {', + '#line %(event_lineno)d "%(event_filename)s"', ' trlen =3D snprintf(ftrace_buf, MAX_TRACE_STRLEN,', ' "%(name)s " %(fmt)s "\\n" %(argnames= )s);', + '#line %(out_next_lineno)d "%(out_filename)s"', ' trlen =3D MIN(trlen, MAX_TRACE_STRLEN - 1);', ' unused =3D write(trace_marker_fd, ftrace_buf, trlen);= ', ' }', @@ -42,6 +44,8 @@ def generate_h(event, group): name=3Devent.name, args=3Devent.args, event_id=3D"TRACE_" + event.name.upper(), + event_lineno=3Devent.lineno, + event_filename=3Devent.filename, fmt=3Devent.fmt.rstrip("\n"), argnames=3Dargnames) =20 diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/l= og.py index 877222bbe9..bc43dbb4f4 100644 --- a/scripts/tracetool/backend/log.py +++ b/scripts/tracetool/backend/log.py @@ -37,12 +37,16 @@ def generate_h(event, group): out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {', ' struct timeval _now;', ' gettimeofday(&_now, NULL);', + '#line %(event_lineno)d "%(event_filename)s"', ' qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s "\\n",', ' qemu_get_thread_id(),', ' (size_t)_now.tv_sec, (size_t)_now.tv_usec', ' %(argnames)s);', + '#line %(out_next_lineno)d "%(out_filename)s"', ' }', cond=3Dcond, + event_lineno=3Devent.lineno, + event_filename=3Devent.filename, name=3Devent.name, fmt=3Devent.fmt.rstrip("\n"), argnames=3Dargnames) diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backen= d/syslog.py index 1373a90192..5a3a00fe31 100644 --- a/scripts/tracetool/backend/syslog.py +++ b/scripts/tracetool/backend/syslog.py @@ -35,9 +35,13 @@ def generate_h(event, group): cond =3D "trace_event_get_state(%s)" % ("TRACE_" + event.name.uppe= r()) =20 out(' if (%(cond)s) {', + '#line %(event_lineno)d "%(event_filename)s"', ' syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);', + '#line %(out_next_lineno)d "%(out_filename)s"', ' }', cond=3Dcond, + event_lineno=3Devent.lineno, + event_filename=3Devent.filename, name=3Devent.name, fmt=3Devent.fmt.rstrip("\n"), argnames=3Dargnames) --=20 2.29.2