Show a patch.

GET /api/1.1/patches/14032/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 14032,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/14032/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/14032/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20211003223606.20016-5-laurent.pinchart@ideasonboard.com>",
    "date": "2021-10-03T22:36:06",
    "name": "[libcamera-devel,v2,4/4] libcamera: base: backtrace: Fallback to libunwind for symbolic names",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "543de4ef0d1661ffde4314273880072cd3f73011",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/14032/mbox/",
    "series": [
        {
            "id": 2593,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2593/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2593",
            "date": "2021-10-03T22:36:03",
            "name": "libcamera: Improve backtraces",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2593/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/14032/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/14032/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 53E26C3243\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  3 Oct 2021 22:36:20 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1ED5E691BD;\n\tMon,  4 Oct 2021 00:36:20 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 06DF9691AB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  4 Oct 2021 00:36:16 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A01FABBE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  4 Oct 2021 00:36:15 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"A/lpWgb8\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1633300575;\n\tbh=ki5qP9STRFGGy76kN6KZ6o68HKpO2X2OhTh2EvrumMM=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=A/lpWgb8E68h7si/M7mmVpMAwfy8ss4igJLuP83d58SuJckTG4NAkIiUDr3NyNwtX\n\t953YwMYD00rSzSfxz3qZqdMiZM6cbHLU3buC6yhBvktsNxBlEFGqXfEvtzDf+eREqF\n\tseRGg8aBhVZALLVJNJQGktgpBP+E1v6slQ6494qM=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  4 Oct 2021 01:36:06 +0300",
        "Message-Id": "<20211003223606.20016-5-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20211003223606.20016-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20211003223606.20016-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 4/4] libcamera: base: backtrace:\n\tFallback to libunwind for symbolic names",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "libunwind has an API to provide symbolic names for functions. It's less\noptimal than using backtrace_symbols() or libdw, as it doesn't allow\ndeferring the symbolic names lookup, but it can be usefull as a fallback\nif no other option is available.\n\nA sample backtrace when falling back to libunwind looks like\n\nlibcamera::VimcCameraData::init()+0xbd\nlibcamera::PipelineHandlerVimc::match(libcamera::DeviceEnumerator*)+0x3e0\nlibcamera::CameraManager::Private::createPipelineHandlers()+0x1a7\nlibcamera::CameraManager::Private::init()+0x98\nlibcamera::CameraManager::Private::run()+0x9f\nlibcamera::Thread::startThread()+0xee\ndecltype(*(std::__1::forward<libcamera::Thread*>(fp0)).*fp()) std::__1::__invoke<void (libcamera::Thread::*)(), libcamera::Thread*, void>(void (libcamera::Thread::*&&)(), libcamera::Thread*&&)+0x77\nvoid std::__1::__thread_execute<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (libcamera::Thread::*)(), libcamera::Thread*, 2ul>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (libcamera::Thread::*)(), libcamera::Thread*>&, std::__1::__tuple_indices<2ul>)+0x3e\nvoid* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (libcamera::Thread::*)(), libcamera::Thread*> >(void*)+0x62\nstart_thread+0xde\n???\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/base/backtrace.h |  1 +\n src/libcamera/base/backtrace.cpp   | 37 +++++++++++++++++++++++++++++-\n 2 files changed, 37 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/include/libcamera/base/backtrace.h b/include/libcamera/base/backtrace.h\nindex 58ccc14c8f81..bb77c73b67e3 100644\n--- a/include/libcamera/base/backtrace.h\n+++ b/include/libcamera/base/backtrace.h\n@@ -30,6 +30,7 @@ private:\n \tbool unwindTrace();\n \n \tstd::vector<void *> backtrace_;\n+\tstd::vector<std::string> backtraceText_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/base/backtrace.cpp b/src/libcamera/base/backtrace.cpp\nindex 0aafc6a366c5..d93e5518670d 100644\n--- a/src/libcamera/base/backtrace.cpp\n+++ b/src/libcamera/base/backtrace.cpp\n@@ -202,6 +202,12 @@ bool Backtrace::unwindTrace()\n \t\treturn false;\n \n \tdo {\n+#if HAVE_BACKTRACE || HAVE_DW\n+\t\t/*\n+\t\t * If backtrace() or libdw is available, they will be used in\n+\t\t * toString() to provide symbol information for the stack\n+\t\t * frames using the IP register value.\n+\t\t */\n \t\tunw_word_t ip;\n \t\tret = unw_get_reg(&cursor, UNW_REG_IP, &ip);\n \t\tif (ret) {\n@@ -210,6 +216,29 @@ bool Backtrace::unwindTrace()\n \t\t}\n \n \t\tbacktrace_.push_back(reinterpret_cast<void *>(ip));\n+#else\n+\t\t/*\n+\t\t * Otherwise, use libunwind to get the symbol information. As\n+\t\t * the libunwind API uses cursors, we can't store the IP values\n+\t\t * and delay symbol lookup to toString().\n+\t\t */\n+\t\tchar symbol[256];\n+\t\tunw_word_t offset = 0;\n+\t\tret = unw_get_proc_name(&cursor, symbol, sizeof(symbol), &offset);\n+\t\tif (ret) {\n+\t\t\tbacktraceText_.emplace_back(\"???\\n\");\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tstd::ostringstream entry;\n+\n+\t\tchar *name = abi::__cxa_demangle(symbol, nullptr, nullptr, nullptr);\n+\t\tentry << (name ? name : symbol);\n+\t\tfree(name);\n+\n+\t\tentry << \"+0x\" << std::hex << offset << \"\\n\";\n+\t\tbacktraceText_.emplace_back(entry.str());\n+#endif\n \t} while (unw_step(&cursor) > 0);\n \n \treturn true;\n@@ -245,9 +274,15 @@ std::string Backtrace::toString(unsigned int skipLevels) const\n \t */\n \tskipLevels += 2;\n \n-\tif (backtrace_.size() <= skipLevels)\n+\tif (backtrace_.size() <= skipLevels &&\n+\t    backtraceText_.size() <= skipLevels)\n \t\treturn std::string();\n \n+\tif (!backtraceText_.empty()) {\n+\t\tSpan<const std::string> trace{ backtraceText_ };\n+\t\treturn utils::join(trace.subspan(skipLevels), \"\");\n+\t}\n+\n #if HAVE_DW\n \tDwflParser dwfl;\n \n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "4/4"
    ]
}