1af69d88dSmrg/************************************************************************** 2af69d88dSmrg * 3af69d88dSmrg * Copyright 2013 VMware, Inc. 4af69d88dSmrg * All Rights Reserved. 5af69d88dSmrg * 6af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a 7af69d88dSmrg * copy of this software and associated documentation files (the 8af69d88dSmrg * "Software"), to deal in the Software without restriction, including 9af69d88dSmrg * without limitation the rights to use, copy, modify, merge, publish, 10af69d88dSmrg * distribute, sub license, and/or sell copies of the Software, and to 11af69d88dSmrg * permit persons to whom the Software is furnished to do so, subject to 12af69d88dSmrg * the following conditions: 13af69d88dSmrg * 14af69d88dSmrg * The above copyright notice and this permission notice (including the 15af69d88dSmrg * next paragraph) shall be included in all copies or substantial portions 16af69d88dSmrg * of the Software. 17af69d88dSmrg * 18af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19af69d88dSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20af69d88dSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21af69d88dSmrg * IN NO EVENT SHALL THE AUTHOR AND/OR ITS SUPPLIERS BE LIABLE FOR 22af69d88dSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23af69d88dSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24af69d88dSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25af69d88dSmrg * 26af69d88dSmrg **************************************************************************/ 27af69d88dSmrg 28af69d88dSmrg 29af69d88dSmrg/* 30af69d88dSmrg * Small utility to disassemble a memory dump of TGSI tokens. 31af69d88dSmrg * 32af69d88dSmrg * Dump can be easily obtained from gdb through the tgsi_dump.gdb helper: 33af69d88dSmrg * 34af69d88dSmrg * (gdb) source tgsi_dump.gdb 35af69d88dSmrg * (gdb) tgsi_dump state->tokens 36af69d88dSmrg * 37af69d88dSmrg * which will generate a tgsi_dump.bin file in the current directory. 38af69d88dSmrg */ 39af69d88dSmrg 40af69d88dSmrg 41af69d88dSmrg#include <stdio.h> 42af69d88dSmrg#include <stdlib.h> 43af69d88dSmrg 44af69d88dSmrg#include "pipe/p_shader_tokens.h" 45af69d88dSmrg#include "tgsi/tgsi_dump.h" 46af69d88dSmrg 47af69d88dSmrg 48af69d88dSmrgstatic void 49af69d88dSmrgusage(const char *arg0) 50af69d88dSmrg{ 51af69d88dSmrg fprintf(stderr, "usage: %s [ options ] <tgsi_dump.bin> ...\n", arg0); 52af69d88dSmrg} 53af69d88dSmrg 54af69d88dSmrg 55af69d88dSmrgstatic void 56af69d88dSmrgdisasm(const char *filename) 57af69d88dSmrg{ 58af69d88dSmrg FILE *fp; 59af69d88dSmrg const size_t max_tokens = 1024*1024; 60af69d88dSmrg struct tgsi_token *tokens; 61af69d88dSmrg 62af69d88dSmrg fp = fopen(filename, "rb"); 63af69d88dSmrg if (!fp) { 64af69d88dSmrg exit(1); 65af69d88dSmrg } 66af69d88dSmrg tokens = malloc(max_tokens * sizeof *tokens); 67af69d88dSmrg fread(tokens, sizeof *tokens, max_tokens, fp); 68af69d88dSmrg 69af69d88dSmrg tgsi_dump(tokens, 0); 70af69d88dSmrg 71af69d88dSmrg free(tokens); 72af69d88dSmrg fclose(fp); 73af69d88dSmrg} 74af69d88dSmrg 75af69d88dSmrg 76af69d88dSmrgint main( int argc, char *argv[] ) 77af69d88dSmrg{ 78af69d88dSmrg int i; 79af69d88dSmrg 80af69d88dSmrg if (argc < 2) { 81af69d88dSmrg usage(argv[0]); 82af69d88dSmrg return 0; 83af69d88dSmrg } 84af69d88dSmrg 85af69d88dSmrg for (i = 1; i < argc; ++i) { 86af69d88dSmrg disasm(argv[i]); 87af69d88dSmrg } 88af69d88dSmrg 89af69d88dSmrg return 0; 90af69d88dSmrg} 91