Skip to content

Commit edba6c8

Browse files
Copilotbrianrob
andcommitted
Fix duplicate stringTable elements in instrumentation manifest
Added HashSet tracking to prevent duplicate string IDs when generating stringTable entries in GetManifestForRegisteredProvider(). This prevents duplicates for keywords, tasks, opcodes, and enum map values. Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
1 parent 06b2d65 commit edba6c8

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/TraceEvent/RegisteredTraceEventParser.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public static string GetManifestForRegisteredProvider(Guid providerGuid)
105105
Dictionary<string, string> enumIntern = new Dictionary<string, string>();
106106
StringWriter enumLocalizations = new StringWriter();
107107

108+
// Track emitted string IDs to prevent duplicates in the stringTable
109+
HashSet<string> emittedStringIds = new HashSet<string>();
110+
108111
// Any task names used so far
109112
Dictionary<string, int> taskNames = new Dictionary<string, int>();
110113
// Any es used so far
@@ -374,7 +377,11 @@ public static string GetManifestForRegisteredProvider(Guid providerGuid)
374377
int value = mapEntries[k].Value;
375378
string valueName = new string((char*)(&enumBuffer[mapEntries[k].NameOffset])).Trim();
376379
enumWriter.WriteLine(" <map value=\"0x{0:x}\" message=\"$(string.map_{1}{2})\"/>", value, enumName, valueName);
377-
enumLocalizations.WriteLine(" <string id=\"map_{0}{1}\" value=\"{2}\"/>", enumName, valueName, valueName);
380+
string stringId = string.Format("map_{0}{1}", enumName, valueName);
381+
if (emittedStringIds.Add(stringId))
382+
{
383+
enumLocalizations.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", stringId, valueName);
384+
}
378385
}
379386
if (enumInfo->Flag == MAP_FLAGS.EVENTMAP_INFO_FLAG_MANIFEST_VALUEMAP)
380387
{
@@ -453,7 +460,11 @@ public static string GetManifestForRegisteredProvider(Guid providerGuid)
453460
{
454461
manifest.WriteLine(" <keyword name=\"{0}\" message=\"$(string.keyword_{1})\" mask=\"0x{2:x}\"/>",
455462
keyValue.Value, keyValue.Value, keyValue.Key);
456-
localizedStrings.WriteLine(" <string id=\"keyword_{0}\" value=\"{1}\"/>", keyValue.Value, keyValue.Value);
463+
string stringId = string.Format("keyword_{0}", keyValue.Value);
464+
if (emittedStringIds.Add(stringId))
465+
{
466+
localizedStrings.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", stringId, keyValue.Value);
467+
}
457468
}
458469
manifest.WriteLine(" </keywords>");
459470
}
@@ -464,7 +475,11 @@ public static string GetManifestForRegisteredProvider(Guid providerGuid)
464475
var task = tasks[taskValue];
465476
manifest.WriteLine(" <task name=\"{0}\" message=\"$(string.task_{1})\" value=\"{2}\"{3}>", task.Name, task.Name, taskValue,
466477
task.Opcodes == null ? "/" : ""); // If no opcodes, terminate immediately.
467-
localizedStrings.WriteLine(" <string id=\"task_{0}\" value=\"{1}\"/>", task.Name, task.Name);
478+
string taskStringId = string.Format("task_{0}", task.Name);
479+
if (emittedStringIds.Add(taskStringId))
480+
{
481+
localizedStrings.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", taskStringId, task.Name);
482+
}
468483
if (task.Opcodes != null)
469484
{
470485
manifest.WriteLine(">");
@@ -473,7 +488,11 @@ public static string GetManifestForRegisteredProvider(Guid providerGuid)
473488
{
474489
manifest.WriteLine(" <opcode name=\"{0}\" message=\"$(string.opcode_{1}{2})\" value=\"{3}\"/>",
475490
keyValue.Value, task.Name, keyValue.Value, keyValue.Key);
476-
localizedStrings.WriteLine(" <string id=\"opcode_{0}{1}\" value=\"{2}\"/>", task.Name, keyValue.Value, keyValue.Value);
491+
string opcodeStringId = string.Format("opcode_{0}{1}", task.Name, keyValue.Value);
492+
if (emittedStringIds.Add(opcodeStringId))
493+
{
494+
localizedStrings.WriteLine(" <string id=\"{0}\" value=\"{1}\"/>", opcodeStringId, keyValue.Value);
495+
}
477496
}
478497
manifest.WriteLine(" </opcodes>");
479498
manifest.WriteLine(" </task>");

0 commit comments

Comments
 (0)