{"record":{"id":"da7cbd9ae9e8ffd1","repo":"Tencent/matrix","slug":"failed-to-create-maps-txt","errorCode":null,"errorMessage":"Failed to create maps.txt","messagePattern":"Failed to create maps\\.txt","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-backtrace/src/main/cpp/external/libunwindstack/tools/unwind_for_offline.cpp","lineNumber":311,"sourceCode":"    }\n  }\n\n  for (size_t i = 0; i < unwinder.NumFrames(); i++) {\n    printf(\"%s\\n\", unwinder.FormatFrame(i).c_str());\n  }\n\n  if (!SaveStack(pid, stacks)) {\n    return 1;\n  }\n\n  std::vector<std::pair<uint64_t, map_info_t>> sorted_maps(maps_by_start.begin(),\n                                                           maps_by_start.end());\n  std::sort(sorted_maps.begin(), sorted_maps.end(),\n            [](auto& a, auto& b) { return a.first < b.first; });\n\n  std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(\"maps.txt\", \"w+\"), &fclose);\n  if (fp == nullptr) {\n    perror(\"Failed to create maps.txt\");\n    return false;\n  }\n\n  for (auto& element : sorted_maps) {\n    char perms[5] = {\"---p\"};\n    map_info_t& map = element.second;\n    if (map.flags & PROT_READ) {\n      perms[0] = 'r';\n    }\n    if (map.flags & PROT_WRITE) {\n      perms[1] = 'w';\n    }\n    if (map.flags & PROT_EXEC) {\n      perms[2] = 'x';\n    }\n    fprintf(fp.get(), \"%\" PRIx64 \"-%\" PRIx64 \" %s %\" PRIx64 \" 00:00 0\", map.start, map.end, perms,\n            map.offset);\n    if (!map.name.empty()) {","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-backtrace/src/main/cpp/external/libunwindstack/tools/unwind_for_offline.cpp#L293-L329","documentation":"SaveData() in unwind_for_offline writes the sorted /proc/<pid>/maps entries to 'maps.txt' with fopen(\"maps.txt\",\"w+\"). A null FILE* makes the tool print 'Failed to create maps.txt' (plus the errno detail from perror) and return false, so the offline unwind bundle cannot be produced. This is the first file the tool tries to create, so its failure usually blocks the whole capture.","triggerScenarios":"fopen(\"maps.txt\") fails in the tool's working directory: read-only filesystem, permission denied, disk full, or name collision with an existing directory; called from main after reading process maps.","commonSituations":"Running the tool in adb shell from /system or another unwritable path, SELinux denials on device, or CI containers with read-only workdirs while collecting maps for offline symbolication.","solutions":["Start the tool from a writable directory (e.g. /data/local/tmp or $HOME)","Address the errno from perror: chmod/chown the directory or free disk space","Delete/rename any blocking maps.txt directory or file","Patch the tool to accept an output directory argument"],"exampleFix":"// before\nfp(fopen(\"maps.txt\", \"w+\"), &fclose);\n// after\nconst char *out = getenv(\"UNWIND_OUT\") ? getenv(\"UNWIND_OUT\") : \"maps.txt\";\nfp(fopen(out, \"w+\"), &fclose);","handlingStrategy":"validation","validationCode":"if (access(\".\", W_OK) != 0) { fprintf(stderr, \"cwd not writable for maps.txt\\n\"); return 1; }","typeGuard":null,"tryCatchPattern":"FILE *fp = fopen(\"maps.txt\", \"w+\");\nif (!fp) { perror(\"Failed to create maps.txt\"); fp = fopen(\"/data/local/tmp/maps.txt\", \"w+\"); }\nif (!fp) return false;","preventionTips":["Launch unwind_for_offline from a writable cwd (e.g. /data/local/tmp)","Confirm SELinux allows file creation for the executing uid","Check free space before running captures","Use an output-dir flag/patch rather than relying on cwd"],"tags":["file-io","android","unwind","maps","debug-tools"],"backgroundTag":"file-open-failed","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}