Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Darwin] Add a MdnsContexts::Print method for debugging purposes #36763

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/platform/Darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ static_library("Darwin") {
"MTRUUIDHelperImpl.mm",
]
}

if (is_debug) {
defines = [ "MDNS_DEBUG=1" ]
} else {
defines = [ "MDNS_DEBUG=0" ]
}
}

source_set("tracing") {
Expand Down
30 changes: 30 additions & 0 deletions src/platform/Darwin/DnssdContexts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,36 @@ CHIP_ERROR MdnsContexts::Has(GenericContext * context)
return CHIP_ERROR_KEY_NOT_FOUND;
}

#if MDNS_DEBUG
void MdnsContexts::Print() const
{
ChipLogDetail(Discovery, "MdnsContexts:");
std::vector<GenericContext *>::const_iterator iter = mContexts.cbegin();
while (iter != mContexts.cend())
{
const char * contextType = "Unknown";
switch ((*iter)->type)
{
case ContextType::Register:
contextType = "Register";
break;
case ContextType::Browse:
contextType = "Browse";
break;
case ContextType::BrowseWithDelegate:
contextType = "BrowseWithDelegate";
break;
case ContextType::Resolve:
contextType = "Resolve";
break;
}

ChipLogDetail(Discovery, "\t%p: %s", *iter, contextType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the value of printing pointer values here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have multiple resolves in flight simultaneously. When debugging, printing the pointer serves as a unique identifier, making it easier to track which resolve operation is performing which actions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, let's add that as a comment.

iter++;
}
}
#endif // DEBUG

CHIP_ERROR MdnsContexts::GetRegisterContextOfTypeAndName(const char * type, const char * name, RegisterContext ** context)
{
bool found = false;
Expand Down
3 changes: 3 additions & 0 deletions src/platform/Darwin/DnssdImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class MdnsContexts
CHIP_ERROR Remove(GenericContext * context);
CHIP_ERROR RemoveAllOfType(ContextType type);
CHIP_ERROR Has(GenericContext * context);
#if MDNS_DEBUG
void Print() const;
#endif

/**
* @brief
Expand Down
Loading