Skip to content

Commit

Permalink
Add a debug info dump command
Browse files Browse the repository at this point in the history
This adds an optional DebugDump() interface to filesystem and file
archive objects.  It can be used to output detailed human-readable
information about a file for debugging purposes.  Currently this is
only implemented for HFS (which had the debug code but nothing to
call it).

The interface is invoked by the new "debug-show-info" command.
  • Loading branch information
fadden committed Feb 22, 2025
1 parent 724dbdb commit aee475b
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 9 deletions.
3 changes: 3 additions & 0 deletions DiskArc/Arc/AppleLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,8 @@ public void AddPart(IFileEntry entry, FilePart part, IPartSource partSource,
public void DeletePart(IFileEntry entry, FilePart part) {
throw new InvalidOperationException("This archive format is read-only");
}

// IArchive
public string? DebugDump() { return null; }
}
}
3 changes: 3 additions & 0 deletions DiskArc/Arc/AppleSingle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,8 @@ private void CheckModAccess(IFileEntry ientry) {
Debug.Assert(entry.ChangeObject != null);
}
}

// IArchive
public string? DebugDump() { return null; }
}
}
3 changes: 3 additions & 0 deletions DiskArc/Arc/AudioRecording.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,8 @@ public void AddPart(IFileEntry entry, FilePart part, IPartSource partSource,
public void DeletePart(IFileEntry entry, FilePart part) {
throw new InvalidOperationException("This archive format is read-only");
}

// IArchive
public string? DebugDump() { return null; }
}
}
3 changes: 3 additions & 0 deletions DiskArc/Arc/Binary2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ public void DeletePart(IFileEntry ientry, FilePart part) {
IsReconstructionNeeded = true;
}

// IArchive
public string? DebugDump() { return null; }

/// <summary>
/// Confirms that we are allowed to modify this entry.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/Arc/GZip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,5 +373,8 @@ public static string StripGZExtension(string pathName) {
return pathName;
}
}

// IArchive
public string? DebugDump() { return null; }
}
}
3 changes: 3 additions & 0 deletions DiskArc/Arc/MacBinary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,8 @@ public void AddPart(IFileEntry entry, FilePart part, IPartSource partSource,
public void DeletePart(IFileEntry entry, FilePart part) {
throw new InvalidOperationException("This archive format is read-only");
}

// IArchive
public string? DebugDump() { return null; }
}
}
3 changes: 3 additions & 0 deletions DiskArc/Arc/NuFX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@ public void DeletePart(IFileEntry ientry, FilePart part) {
((NuFX_FileEntry)ientry).DeletePart(part);
}

// IArchive
public string? DebugDump() { return null; }

/// <summary>
/// Confirms that we are allowed to modify this entry.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/Arc/Zip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,9 @@ public void DeletePart(IFileEntry ientry, FilePart part) {
((Zip_FileEntry)ientry).DeletePart();
}

// IArchive
public string? DebugDump() { return null; }

/// <summary>
/// Confirms that we are allowed to modify this entry.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/FS/CPM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ public override string ToString() {
return "[CP/M" + rawStr + "]";
}

// IFileSystem
public string? DebugDump() { return null; }

// IDisposable generic finalizer.
~CPM() {
Dispose(false);
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/FS/DOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ public override string ToString() {
return "[DOS " + id + "]";
}

// IFileSystem
public string? DebugDump() { return null; }


// IDisposable generic finalizer.
~DOS() {
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/FS/Gutenberg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ public override string ToString() {
return "[Gutenberg (" + id + ")]";
}

// IFileSystem
public string? DebugDump() { return null; }

// IDisposable generic finalizer.
~Gutenberg() {
Dispose(false);
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/FS/HFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ public override string ToString() {
return "[HFS vol: " + id + "]";
}

// IFileSystem
public string? DebugDump() { return HFS_Dump.Dump(this); }

// IDisposable generic finalizer.
~HFS() {
Dispose(false);
Expand Down
1 change: 1 addition & 0 deletions DiskArc/FS/HFS_Dump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static string Dump(HFS fs) {
sb.AppendLine("Total Files : " + mdb.FileCount);
sb.AppendLine("Total Dirs : " + mdb.DirCount);
sb.AppendLine("Next CNID : " + mdb.NextCatalogID);
sb.AppendLine("Blessed system CNID: " + mdb.FndrInfo[0]);

sb.AppendLine("Vol Bitmap Start : " + mdb.VolBitmapStart);
sb.AppendLine("Free Blocks : " + mdb.FreeBlocks);
Expand Down
7 changes: 7 additions & 0 deletions DiskArc/FS/HFS_MDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ public uint DirCount {

/// <summary>drFndrInfo: information used by the Macintosh Finder.</summary>
private uint[] drFndrInfo = new uint[8];
public uint[] FndrInfo {
get {
uint[] copy = new uint[8];
Array.Copy(drFndrInfo, copy, drFndrInfo.Length);
return copy;
}
}

/// <summary>drVCSize / drEmbedSigWord: originally, size (in allocation blocks) of the
/// volume cache. Changed to embedded volume signature.</summary>
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/FS/MFS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ public override string ToString() {
return "[MFS (" + id + ")]";
}

// IFileSystem
public string? DebugDump() { return null; }

// IDisposable generic finalizer.
~MFS() {
Dispose(false);
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/FS/Pascal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public override string ToString() {
return "[Pascal vol '" + id + "']";
}

// IFileSystem
public string? DebugDump() { return null; }

// IDisposable generic finalizer.
~Pascal() {
Dispose(false);
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/FS/ProDOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ public override string ToString() {
return "[ProDOS vol '" + id + "']";
}

// IFileSystem
public string? DebugDump() { return null; }

// IDisposable generic finalizer.
~ProDOS() {
Dispose(false);
Expand Down
3 changes: 3 additions & 0 deletions DiskArc/FS/RDOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ public override string ToString() {
return "[RDOS (" + id + ")]";
}

// IFileSystem
public string? DebugDump() { return null; }

// IDisposable generic finalizer.
~RDOS() {
Dispose(false);
Expand Down
6 changes: 6 additions & 0 deletions DiskArc/IArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,11 @@ void AddPart(IFileEntry entry, Defs.FilePart part, IPartSource partSource,
/// <exception cref="NotSupportedException">This type of archive does not allow this
/// part.</exception>
void DeletePart(IFileEntry entry, Defs.FilePart part);

/// <summary>
/// Generates detailed human-readable information about the archive.
/// </summary>
/// <returns>Formatted text, or null if not implemented.</returns>
string? DebugDump();
}
}
6 changes: 6 additions & 0 deletions DiskArc/IFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,11 @@ enum FileAccessMode {
/// Closes all open files.
/// </summary>
void CloseAll();

/// <summary>
/// Generates detailed human-readable information about the filesystem.
/// </summary>
/// <returns>Formatted text, or null if not implemented.</returns>
string? DebugDump();
}
}
7 changes: 6 additions & 1 deletion cp2/CP2Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,16 @@ public Command(string[] names, string summary, string usage, bool needsArchive,
usage: "",
needsArchive: false, acceptsMultipleArgs: false,
handler: HandleCrash),
new Command(names: new string[] { "debug-show-info" },
summary: "displays detailed archive-specific information",
usage: "<ext-archive>",
needsArchive: true, acceptsMultipleArgs: false,
handler: DebugCmd.HandleShowInfo),
new Command(names: new string[] { "debug-wtree" },
summary: "displays work tree for an archive",
usage: "<archive>",
needsArchive: true, acceptsMultipleArgs: false,
handler: Tests.DebugWorkTree.HandleDumpTree),
handler: DebugCmd.HandleDumpWTree),
new Command(names: new string[] { "debug-test" },
summary: "executes program tests",
usage: "",
Expand Down
77 changes: 69 additions & 8 deletions cp2/Tests/DebugWorkTree.cs → cp2/DebugCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,90 @@
using System.Diagnostics;

using AppCommon;
using CommonUtil;
using DiskArc.Arc;
using DiskArc.Multi;
using DiskArc;
using static AppCommon.WorkTree;

namespace cp2.Tests {
public static class DebugWorkTree {
namespace cp2 {
public static class DebugCmd {
/// <summary>
/// Handles "debug-wtree" command.
/// Handles "debug-show-info" command.
/// </summary>
public static bool HandleDumpTree(string cmdName, string[] args, ParamsBag parms) {
public static bool HandleShowInfo(string cmdName, string[] args, ParamsBag parms) {
Debug.Assert(args.Length == 1);
if (!ExtArchive.OpenExtArc(args[0], false, true, parms, out DiskArcNode? rootNode,
out DiskArcNode? leafNode, out object? leaf, out IFileEntry endDirEntry)) {
return false;
}
Debug.Assert(rootNode != null && leaf != null);

using (rootNode) {
string? hdrStr = null;
string? outStr = null;
if (leaf is IArchive) {
IArchive archive = (IArchive)leaf;
hdrStr = "--- " + ThingString.IArchive(archive) + " ---";
outStr = archive.DebugDump();
} else if (leaf is IDiskImage) {
IDiskImage disk = (IDiskImage)leaf;
if (disk.Contents is IFileSystem) {
IFileSystem fs = (IFileSystem)disk.Contents;
hdrStr = "--- " + ThingString.IFileSystem(fs) + " ---";
outStr = fs.DebugDump();
} else if (disk.Contents is IMultiPart) {
outStr = "No info available for multi-part filesystem.";
} else {
Console.Error.WriteLine("Error: disk image contents not recognized");
return false;
}
} else if (leaf is Partition) {
Partition part = (Partition)leaf;
if (part.FileSystem == null) {
part.AnalyzePartition();
}
if (part.FileSystem != null) {
hdrStr = "--- " + ThingString.IFileSystem(part.FileSystem) + " ---";
outStr = part.FileSystem.DebugDump();
} else {
outStr = "Partition has unknown contents.";
}
} else {
Console.Error.WriteLine("Internal issue: what is " + leaf);
Debug.Assert(false);
return false;
}
if (hdrStr != null) {
Console.WriteLine(hdrStr);
}
if (outStr != null) {
Console.WriteLine(outStr);
} else {
Console.WriteLine("Debug info not available.");
}
return true;
}
}


/// <summary>
/// Handles "debug-wtree" command. This displays the WorkTree structure, which is
/// only used by the GUI app.
/// </summary>
public static bool HandleDumpWTree(string cmdName, string[] args, ParamsBag parms) {
if (args.Length != 1) {
CP2Main.ShowUsage(cmdName);
return false;
}

string extArchive = args[0];
string fileName = args[0]; // not processing ext-archive strings

// Include the config parameters in the closure.
DepthLimiter limiter =
delegate (DepthParentKind parentKind, DepthChildKind childKind) {
return DepthLimit(parentKind, childKind, parms.Depth);
};
using (WorkTree tree = new WorkTree(extArchive, limiter, true, null, parms.AppHook)) {
};
using (WorkTree tree = new WorkTree(fileName, limiter, true, null, parms.AppHook)) {
Console.Write(tree.GenerateTreeSummary());
}

Expand Down

0 comments on commit aee475b

Please sign in to comment.