{"action":"created","comment":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/comments/75337488","id":75337488,"diff_hunk":"@@ -0,0 +1,127 @@\n+/* mbed Microcontroller Library\n+ * Copyright (c) 2006-2016 ARM Limited\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#include <stdlib.h>\n+#include <stdarg.h>\n+#include <stdio.h>\n+#include \"mbed_mem_trace.h\"\n+#include \"critical.h\"\n+#include \"toolchain.h\"\n+\n+/******************************************************************************\n+ * Internal variables, functions and helpers\n+ *****************************************************************************/\n+\n+/* The current tracing mask (see mbed_mem_trace.h for details). */\n+static uint8_t mem_trace_mask = MBED_MEM_TRACE_DISABLE;\n+/* The callback function that will be called after a traced memory operations finishes. */\n+static mbed_mem_trace_cb_t mem_trace_cb;\n+/* 'already_tracing' guards \"trace inside trace\" situations (for example, the implementation\n+ * of realloc() might call malloc() internally, and since malloc() is also traced, this could\n+ * result in two calls to the callback function instead of one. */\n+static uint8_t already_tracing;\n+\n+/******************************************************************************\n+ * Public interface\n+ *****************************************************************************/\n+\n+void mbed_mem_trace_setup(uint8_t mask, mbed_mem_trace_cb_t cb) {\n+    mem_trace_mask = mask;\n+    mem_trace_cb = cb;\n+}\n+\n+void* mbed_mem_trace_malloc(void *res, size_t size) {\n+    uint8_t expected = 0;\n+\n+    if (mem_trace_cb && (mem_trace_mask & MBED_MEM_TRACE_MALLOC)) {\n+        if (core_util_atomic_cas_u8(&already_tracing, &expected, 1)) {\n+            mem_trace_cb(MBED_MEM_TRACE_MALLOC, res, MBED_CALLER_ADDR(), size);\n+            already_tracing = 0;\n+        }\n+    }\n+    return res;\n+}\n+\n+void* mbed_mem_trace_realloc(void *res, void *ptr, size_t size) {\n+    uint8_t expected = 0;\n+\n+    if (mem_trace_cb && (mem_trace_mask & MBED_MEM_TRACE_REALLOC)) {\n+        if (core_util_atomic_cas_u8(&already_tracing, &expected, 1)) {\n+            mem_trace_cb(MBED_MEM_TRACE_REALLOC, res, MBED_CALLER_ADDR(), ptr, size);\n+            already_tracing = 0;\n+        }\n+    }\n+    return res;\n+}\n+\n+void* mbed_mem_trace_calloc(void *res, size_t num, size_t size) {\n+    uint8_t expected = 0;\n+\n+    if (mem_trace_cb && (mem_trace_mask & MBED_MEM_TRACE_CALLOC)) {\n+        if (core_util_atomic_cas_u8(&already_tracing, &expected, 1)) {\n+            mem_trace_cb(MBED_MEM_TRACE_CALLOC, res, MBED_CALLER_ADDR(), num, size);\n+            already_tracing = 0;\n+        }\n+    }\n+    return res;\n+}\n+\n+void mbed_mem_trace_free(void *ptr) {\n+    uint8_t expected = 0;\n+\n+    if (mem_trace_cb && (mem_trace_mask & MBED_MEM_TRACE_FREE)) {\n+        if (core_util_atomic_cas_u8(&already_tracing, &expected, 1)) {\n+            mem_trace_cb(MBED_MEM_TRACE_FREE, NULL, MBED_CALLER_ADDR(), ptr);\n+            already_tracing = 0;\n+        }\n+    }\n+}\n+\n+void mbed_mem_default_callback(uint8_t op, void *res, void *caller, ...) {\n+    va_list va;\n+    size_t temp_s1, temp_s2;\n+    void *temp_ptr;\n+\n+    va_start(va, caller);\n+    switch(op) {\n+        case MBED_MEM_TRACE_MALLOC:\n+            temp_s1 = va_arg(va, size_t);\n+            printf(MBED_MEM_DEFAULT_TRACER_PREFIX \"m:%p;%p-%u\\n\", res, caller, temp_s1);","path":"hal/common/mbed_mem_trace.c","position":102,"original_position":102,"commit_id":"cf1011cc41af1cda38707a50baa69e8321d130fd","original_commit_id":"cf1011cc41af1cda38707a50baa69e8321d130fd","user":{"login":"bogdanm","id":211717,"avatar_url":"https://avatars.githubusercontent.com/u/211717?v=3","gravatar_id":"","url":"https://api.github.com/users/bogdanm","html_url":"https://github.com/bogdanm","followers_url":"https://api.github.com/users/bogdanm/followers","following_url":"https://api.github.com/users/bogdanm/following{/other_user}","gists_url":"https://api.github.com/users/bogdanm/gists{/gist_id}","starred_url":"https://api.github.com/users/bogdanm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bogdanm/subscriptions","organizations_url":"https://api.github.com/users/bogdanm/orgs","repos_url":"https://api.github.com/users/bogdanm/repos","events_url":"https://api.github.com/users/bogdanm/events{/privacy}","received_events_url":"https://api.github.com/users/bogdanm/received_events","type":"User","site_admin":false},"body":"Interesting point, thank you. I've never used mbed-trace myself, but I'll take a look at it and I'll make the necessary changes.","created_at":"2016-08-18T16:04:59Z","updated_at":"2016-08-18T16:04:59Z","html_url":"https://github.com/ARMmbed/mbed-os/pull/2487#discussion_r75337488","pull_request_url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/2487","_links":{"self":{"href":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/comments/75337488"},"html":{"href":"https://github.com/ARMmbed/mbed-os/pull/2487#discussion_r75337488"},"pull_request":{"href":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/2487"}}},"pull_request":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/2487","id":81814584,"html_url":"https://github.com/ARMmbed/mbed-os/pull/2487","diff_url":"https://github.com/ARMmbed/mbed-os/pull/2487.diff","patch_url":"https://github.com/ARMmbed/mbed-os/pull/2487.patch","issue_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/2487","number":2487,"state":"open","locked":false,"title":"Runtime dynamic memory tracing","user":{"login":"bogdanm","id":211717,"avatar_url":"https://avatars.githubusercontent.com/u/211717?v=3","gravatar_id":"","url":"https://api.github.com/users/bogdanm","html_url":"https://github.com/bogdanm","followers_url":"https://api.github.com/users/bogdanm/followers","following_url":"https://api.github.com/users/bogdanm/following{/other_user}","gists_url":"https://api.github.com/users/bogdanm/gists{/gist_id}","starred_url":"https://api.github.com/users/bogdanm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bogdanm/subscriptions","organizations_url":"https://api.github.com/users/bogdanm/orgs","repos_url":"https://api.github.com/users/bogdanm/repos","events_url":"https://api.github.com/users/bogdanm/events{/privacy}","received_events_url":"https://api.github.com/users/bogdanm/received_events","type":"User","site_admin":false},"body":"This commit adds a dynamic memory tracer that calls a callback whenever\r\none of the basic memory allocation functions (malloc, realloc, calloc,\r\nfree) is called. The compilation of the tracer is guarded by the\r\n'MBED_FULL_MEM_TRACE_ENABLED` macro.","created_at":"2016-08-18T13:22:44Z","updated_at":"2016-08-18T16:04:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dc2877f817e2d14e41b17545b8b404c5eb0e257e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/2487/commits","review_comments_url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/2487/comments","review_comment_url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/2487/comments","statuses_url":"https://api.github.com/repos/ARMmbed/mbed-os/statuses/cf1011cc41af1cda38707a50baa69e8321d130fd","head":{"label":"ARMmbed:memory_instrumentation","ref":"memory_instrumentation","sha":"cf1011cc41af1cda38707a50baa69e8321d130fd","user":{"login":"ARMmbed","id":8916057,"avatar_url":"https://avatars.githubusercontent.com/u/8916057?v=3","gravatar_id":"","url":"https://api.github.com/users/ARMmbed","html_url":"https://github.com/ARMmbed","followers_url":"https://api.github.com/users/ARMmbed/followers","following_url":"https://api.github.com/users/ARMmbed/following{/other_user}","gists_url":"https://api.github.com/users/ARMmbed/gists{/gist_id}","starred_url":"https://api.github.com/users/ARMmbed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ARMmbed/subscriptions","organizations_url":"https://api.github.com/users/ARMmbed/orgs","repos_url":"https://api.github.com/users/ARMmbed/repos","events_url":"https://api.github.com/users/ARMmbed/events{/privacy}","received_events_url":"https://api.github.com/users/ARMmbed/received_events","type":"Organization","site_admin":false},"repo":{"id":8270972,"name":"mbed-os","full_name":"ARMmbed/mbed-os","owner":{"login":"ARMmbed","id":8916057,"avatar_url":"https://avatars.githubusercontent.com/u/8916057?v=3","gravatar_id":"","url":"https://api.github.com/users/ARMmbed","html_url":"https://github.com/ARMmbed","followers_url":"https://api.github.com/users/ARMmbed/followers","following_url":"https://api.github.com/users/ARMmbed/following{/other_user}","gists_url":"https://api.github.com/users/ARMmbed/gists{/gist_id}","starred_url":"https://api.github.com/users/ARMmbed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ARMmbed/subscriptions","organizations_url":"https://api.github.com/users/ARMmbed/orgs","repos_url":"https://api.github.com/users/ARMmbed/repos","events_url":"https://api.github.com/users/ARMmbed/events{/privacy}","received_events_url":"https://api.github.com/users/ARMmbed/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ARMmbed/mbed-os","description":"ARM mbed OS is a platform operating system designed for the internet of things","fork":false,"url":"https://api.github.com/repos/ARMmbed/mbed-os","forks_url":"https://api.github.com/repos/ARMmbed/mbed-os/forks","keys_url":"https://api.github.com/repos/ARMmbed/mbed-os/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ARMmbed/mbed-os/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ARMmbed/mbed-os/teams","hooks_url":"https://api.github.com/repos/ARMmbed/mbed-os/hooks","issue_events_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/events{/number}","events_url":"https://api.github.com/repos/ARMmbed/mbed-os/events","assignees_url":"https://api.github.com/repos/ARMmbed/mbed-os/assignees{/user}","branches_url":"https://api.github.com/repos/ARMmbed/mbed-os/branches{/branch}","tags_url":"https://api.github.com/repos/ARMmbed/mbed-os/tags","blobs_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/refs{/sha}","trees_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ARMmbed/mbed-os/statuses/{sha}","languages_url":"https://api.github.com/repos/ARMmbed/mbed-os/languages","stargazers_url":"https://api.github.com/repos/ARMmbed/mbed-os/stargazers","contributors_url":"https://api.github.com/repos/ARMmbed/mbed-os/contributors","subscribers_url":"https://api.github.com/repos/ARMmbed/mbed-os/subscribers","subscription_url":"https://api.github.com/repos/ARMmbed/mbed-os/subscription","commits_url":"https://api.github.com/repos/ARMmbed/mbed-os/commits{/sha}","git_commits_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/commits{/sha}","comments_url":"https://api.github.com/repos/ARMmbed/mbed-os/comments{/number}","issue_comment_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/comments{/number}","contents_url":"https://api.github.com/repos/ARMmbed/mbed-os/contents/{+path}","compare_url":"https://api.github.com/repos/ARMmbed/mbed-os/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ARMmbed/mbed-os/merges","archive_url":"https://api.github.com/repos/ARMmbed/mbed-os/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ARMmbed/mbed-os/downloads","issues_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues{/number}","pulls_url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls{/number}","milestones_url":"https://api.github.com/repos/ARMmbed/mbed-os/milestones{/number}","notifications_url":"https://api.github.com/repos/ARMmbed/mbed-os/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ARMmbed/mbed-os/labels{/name}","releases_url":"https://api.github.com/repos/ARMmbed/mbed-os/releases{/id}","deployments_url":"https://api.github.com/repos/ARMmbed/mbed-os/deployments","created_at":"2013-02-18T15:23:11Z","updated_at":"2016-08-18T10:18:42Z","pushed_at":"2016-08-18T15:52:51Z","git_url":"git://github.com/ARMmbed/mbed-os.git","ssh_url":"git@github.com:ARMmbed/mbed-os.git","clone_url":"https://github.com/ARMmbed/mbed-os.git","svn_url":"https://github.com/ARMmbed/mbed-os","homepage":"https://mbed.com","size":71553,"stargazers_count":720,"watchers_count":720,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":706,"mirror_url":null,"open_issues_count":342,"forks":706,"open_issues":342,"watchers":720,"default_branch":"master"}},"base":{"label":"ARMmbed:master","ref":"master","sha":"0f2566b3ff699f1a75eff1cdb1dfb1362bbbfe65","user":{"login":"ARMmbed","id":8916057,"avatar_url":"https://avatars.githubusercontent.com/u/8916057?v=3","gravatar_id":"","url":"https://api.github.com/users/ARMmbed","html_url":"https://github.com/ARMmbed","followers_url":"https://api.github.com/users/ARMmbed/followers","following_url":"https://api.github.com/users/ARMmbed/following{/other_user}","gists_url":"https://api.github.com/users/ARMmbed/gists{/gist_id}","starred_url":"https://api.github.com/users/ARMmbed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ARMmbed/subscriptions","organizations_url":"https://api.github.com/users/ARMmbed/orgs","repos_url":"https://api.github.com/users/ARMmbed/repos","events_url":"https://api.github.com/users/ARMmbed/events{/privacy}","received_events_url":"https://api.github.com/users/ARMmbed/received_events","type":"Organization","site_admin":false},"repo":{"id":8270972,"name":"mbed-os","full_name":"ARMmbed/mbed-os","owner":{"login":"ARMmbed","id":8916057,"avatar_url":"https://avatars.githubusercontent.com/u/8916057?v=3","gravatar_id":"","url":"https://api.github.com/users/ARMmbed","html_url":"https://github.com/ARMmbed","followers_url":"https://api.github.com/users/ARMmbed/followers","following_url":"https://api.github.com/users/ARMmbed/following{/other_user}","gists_url":"https://api.github.com/users/ARMmbed/gists{/gist_id}","starred_url":"https://api.github.com/users/ARMmbed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ARMmbed/subscriptions","organizations_url":"https://api.github.com/users/ARMmbed/orgs","repos_url":"https://api.github.com/users/ARMmbed/repos","events_url":"https://api.github.com/users/ARMmbed/events{/privacy}","received_events_url":"https://api.github.com/users/ARMmbed/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ARMmbed/mbed-os","description":"ARM mbed OS is a platform operating system designed for the internet of things","fork":false,"url":"https://api.github.com/repos/ARMmbed/mbed-os","forks_url":"https://api.github.com/repos/ARMmbed/mbed-os/forks","keys_url":"https://api.github.com/repos/ARMmbed/mbed-os/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ARMmbed/mbed-os/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ARMmbed/mbed-os/teams","hooks_url":"https://api.github.com/repos/ARMmbed/mbed-os/hooks","issue_events_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/events{/number}","events_url":"https://api.github.com/repos/ARMmbed/mbed-os/events","assignees_url":"https://api.github.com/repos/ARMmbed/mbed-os/assignees{/user}","branches_url":"https://api.github.com/repos/ARMmbed/mbed-os/branches{/branch}","tags_url":"https://api.github.com/repos/ARMmbed/mbed-os/tags","blobs_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/refs{/sha}","trees_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ARMmbed/mbed-os/statuses/{sha}","languages_url":"https://api.github.com/repos/ARMmbed/mbed-os/languages","stargazers_url":"https://api.github.com/repos/ARMmbed/mbed-os/stargazers","contributors_url":"https://api.github.com/repos/ARMmbed/mbed-os/contributors","subscribers_url":"https://api.github.com/repos/ARMmbed/mbed-os/subscribers","subscription_url":"https://api.github.com/repos/ARMmbed/mbed-os/subscription","commits_url":"https://api.github.com/repos/ARMmbed/mbed-os/commits{/sha}","git_commits_url":"https://api.github.com/repos/ARMmbed/mbed-os/git/commits{/sha}","comments_url":"https://api.github.com/repos/ARMmbed/mbed-os/comments{/number}","issue_comment_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/comments{/number}","contents_url":"https://api.github.com/repos/ARMmbed/mbed-os/contents/{+path}","compare_url":"https://api.github.com/repos/ARMmbed/mbed-os/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ARMmbed/mbed-os/merges","archive_url":"https://api.github.com/repos/ARMmbed/mbed-os/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ARMmbed/mbed-os/downloads","issues_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues{/number}","pulls_url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls{/number}","milestones_url":"https://api.github.com/repos/ARMmbed/mbed-os/milestones{/number}","notifications_url":"https://api.github.com/repos/ARMmbed/mbed-os/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ARMmbed/mbed-os/labels{/name}","releases_url":"https://api.github.com/repos/ARMmbed/mbed-os/releases{/id}","deployments_url":"https://api.github.com/repos/ARMmbed/mbed-os/deployments","created_at":"2013-02-18T15:23:11Z","updated_at":"2016-08-18T10:18:42Z","pushed_at":"2016-08-18T15:52:51Z","git_url":"git://github.com/ARMmbed/mbed-os.git","ssh_url":"git@github.com:ARMmbed/mbed-os.git","clone_url":"https://github.com/ARMmbed/mbed-os.git","svn_url":"https://github.com/ARMmbed/mbed-os","homepage":"https://mbed.com","size":71553,"stargazers_count":720,"watchers_count":720,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":706,"mirror_url":null,"open_issues_count":342,"forks":706,"open_issues":342,"watchers":720,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/2487"},"html":{"href":"https://github.com/ARMmbed/mbed-os/pull/2487"},"issue":{"href":"https://api.github.com/repos/ARMmbed/mbed-os/issues/2487"},"comments":{"href":"https://api.github.com/repos/ARMmbed/mbed-os/issues/2487/comments"},"review_comments":{"href":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/2487/comments"},"review_comment":{"href":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/2487/commits"},"statuses":{"href":"https://api.github.com/repos/ARMmbed/mbed-os/statuses/cf1011cc41af1cda38707a50baa69e8321d130fd"}}}}
{"actor":{"display_login":"bogdanm"}}