Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: minidump/minidump_thread_id_map.cc

Issue 693933002: Add MinidumpThreadListWriter::InitializeFromSnapshot() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@minidump_init_from_snapshot_context_new
Patch Set: Address review feedback Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « minidump/minidump_thread_id_map.h ('k') | minidump/minidump_thread_id_map_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "minidump/minidump_thread_id_map.h"
16
17 #include <limits>
18 #include <set>
19 #include <utility>
20
21 #include "base/logging.h"
22 #include "snapshot/thread_snapshot.h"
23
24 namespace crashpad {
25
26 void BuildMinidumpThreadIDMap(
27 const std::vector<const ThreadSnapshot*>& thread_snapshots,
28 MinidumpThreadIDMap* thread_id_map) {
29 DCHECK(thread_id_map->empty());
30
31 // First, try truncating each 64-bit thread ID to 32 bits. If that’s possible
32 // for each unique 64-bit thread ID, then this will be used as the mapping.
33 // This preserves as much of the original thread ID as possible when feasible.
34 bool collision = false;
35 std::set<uint32_t> thread_ids_32;
36 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) {
37 uint64_t thread_id_64 = thread_snapshot->ThreadID();
38 if (thread_id_map->find(thread_id_64) == thread_id_map->end()) {
39 uint32_t thread_id_32 = thread_id_64;
40 if (thread_ids_32.find(thread_id_32) != thread_ids_32.end()) {
41 collision = true;
42 break;
43 }
44 thread_ids_32.insert(thread_id_32);
45 thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32));
46 }
47 }
48
49 if (collision) {
50 // Since there was a collision, go back and assign each unique 64-bit thread
51 // ID its own sequential 32-bit equivalent. The 32-bit thread IDs will not
52 // bear any resemblance to the original 64-bit thread IDs.
53 thread_id_map->clear();
54 for (const ThreadSnapshot* thread_snapshot : thread_snapshots) {
55 uint64_t thread_id_64 = thread_snapshot->ThreadID();
56 if (thread_id_map->find(thread_id_64) == thread_id_map->end()) {
57 uint32_t thread_id_32 = thread_id_map->size();
58 thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32));
59 }
60 }
61
62 DCHECK_LE(thread_id_map->size(), std::numeric_limits<uint32_t>::max());
63 }
64 }
65
66 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_thread_id_map.h ('k') | minidump/minidump_thread_id_map_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698